-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Social media profiles to conferences
- Loading branch information
1 parent
2125bb3
commit 794c759
Showing
12 changed files
with
127 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Avo::Resources::SocialProfile < Avo::BaseResource | ||
def fields | ||
field :id, as: :id | ||
field :provider, enum: ::SocialProfile.providers, as: :select, required: true | ||
field :value, as: :text | ||
field :sociable, as: :belongs_to, polymorphic_as: :sociable, types: [::Speaker, ::Event], foreign_key: :slug | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# This controller has been generated to enable Rails' resource routes. | ||
# More information on https://docs.avohq.io/3.0/controllers.html | ||
class Avo::SocialProfilesController < Avo::ResourcesController | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Sociable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_many :social_profiles, as: :sociable, dependent: :destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# == Schema Information | ||
# | ||
# Table name: social_profiles | ||
# | ||
# id :integer not null, primary key | ||
# provider :integer | ||
# sociable_type :string indexed => [sociable_id] | ||
# value :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# sociable_id :integer indexed => [sociable_type] | ||
# | ||
# Indexes | ||
# | ||
# index_social_profiles_on_sociable (sociable_type,sociable_id) | ||
# | ||
class SocialProfile < ApplicationRecord | ||
belongs_to :sociable, polymorphic: true | ||
|
||
enum :provider, { | ||
github: 0, | ||
twitter: 1, | ||
linkedin: 2, | ||
bsky: 3, | ||
mastadon: 4 | ||
}, | ||
suffix: true, | ||
validate: {presence: true} | ||
|
||
before_save do | ||
self.value = self.class.normalize_value_for(provider.to_sym, value) | ||
end | ||
|
||
# normalizes | ||
normalizes :github, with: ->(value) { value.gsub(/^(?:https?:\/\/)?(?:www\.)?github\.com\//, "").gsub(/^@/, "") } | ||
normalizes :twitter, with: ->(value) { value.gsub(%r{https?://(?:www\.)?(?:x\.com|twitter\.com)/}, "").gsub(/@/, "") } | ||
normalizes :linkedin, with: ->(value) { value.gsub(%r{https?://(?:www\.)?(?:linkedin\.com/in)/}, "") } | ||
normalizes :bsky, with: ->(value) { value.gsub(%r{https?://(?:www\.)?(?:[^\/]+\.com)/}, "").gsub(/@/, "") } | ||
normalizes :mastodon, with: ->(value) { | ||
return value if value&.match?(URI::DEFAULT_PARSER.make_regexp) | ||
return "" unless value.count("@") == 2 | ||
|
||
_, handle, instance = value.split("@") | ||
|
||
"https://#{instance}/@#{handle}" | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateSocialProfiles < ActiveRecord::Migration[8.0] | ||
def change | ||
create_table :social_profiles do |t| | ||
t.string :value | ||
t.integer :provider | ||
t.belongs_to :sociable, polymorphic: true | ||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
# model remove the "{}" from the fixture names and add the columns immediately | ||
# below each fixture, per the syntax in the comments below | ||
# | ||
# == Schema Information | ||
# | ||
# Table name: social_profiles | ||
# | ||
# id :integer not null, primary key | ||
# provider :integer | ||
# sociable_type :string indexed => [sociable_id] | ||
# value :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# sociable_id :integer indexed => [sociable_type] | ||
# | ||
# Indexes | ||
# | ||
# index_social_profiles_on_sociable (sociable_type,sociable_id) | ||
# | ||
one: {} | ||
# column: value | ||
# | ||
two: {} | ||
# column: value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class SocialProfileTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |