Commit 51cb598ffd8665e20ac3f53a8b61da66fcc52d6b
1 parent
a4dae44e
Moves relations to concerns
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Showing
6 changed files
with
9 additions
and
10 deletions
Show diff stats
app/models/concerns/followable.rb
| 1 | module Followable | 1 | module Followable |
| 2 | extend ActiveSupport::Concern | 2 | extend ActiveSupport::Concern |
| 3 | 3 | ||
| 4 | + included do | ||
| 5 | + has_many :profile_followers, :as => :profile | ||
| 6 | + has_many :circles, :through => :profile_followers | ||
| 7 | + end | ||
| 8 | + | ||
| 4 | def followers | 9 | def followers |
| 5 | person_followers = Person.joins(:owned_circles).merge(circles).uniq | 10 | person_followers = Person.joins(:owned_circles).merge(circles).uniq |
| 6 | external_person_followers = ExternalPerson.joins(:owned_circles).merge(circles).uniq | 11 | external_person_followers = ExternalPerson.joins(:owned_circles).merge(circles).uniq |
app/models/concerns/follower.rb
| 1 | module Follower | 1 | module Follower |
| 2 | extend ActiveSupport::Concern | 2 | extend ActiveSupport::Concern |
| 3 | 3 | ||
| 4 | + included do | ||
| 5 | + has_many :owned_circles, as: :owner, :class_name => "Circle" | ||
| 6 | + end | ||
| 7 | + | ||
| 4 | def follow(profile, circles) | 8 | def follow(profile, circles) |
| 5 | circles = [circles] unless circles.is_a?(Array) | 9 | circles = [circles] unless circles.is_a?(Array) |
| 6 | circles.each do |new_circle| | 10 | circles.each do |new_circle| |
app/models/external_person.rb
| @@ -5,10 +5,7 @@ class ExternalPerson < ExternalProfile | @@ -5,10 +5,7 @@ class ExternalPerson < ExternalProfile | ||
| 5 | include ProfileEntity | 5 | include ProfileEntity |
| 6 | include Follower | 6 | include Follower |
| 7 | 7 | ||
| 8 | - has_many :owned_circles, as: :owner, :class_name => "Circle" | ||
| 9 | - | ||
| 10 | validates_uniqueness_of :identifier, scope: :source | 8 | validates_uniqueness_of :identifier, scope: :source |
| 11 | - | ||
| 12 | validates_presence_of :source, :email, :created_at | 9 | validates_presence_of :source, :email, :created_at |
| 13 | 10 | ||
| 14 | attr_accessible :source, :email, :created_at | 11 | attr_accessible :source, :email, :created_at |
app/models/external_profile.rb
| @@ -2,9 +2,6 @@ class ExternalProfile < ActiveRecord::Base | @@ -2,9 +2,6 @@ class ExternalProfile < ActiveRecord::Base | ||
| 2 | 2 | ||
| 3 | include Followable | 3 | include Followable |
| 4 | 4 | ||
| 5 | - has_many :profile_followers, :as => :profile | ||
| 6 | - has_many :circles, :through => :profile_followers | ||
| 7 | - | ||
| 8 | def name | 5 | def name |
| 9 | "#{self[:name]}@#{self.source}" | 6 | "#{self[:name]}@#{self.source}" |
| 10 | end | 7 | end |
app/models/person.rb
| @@ -94,7 +94,6 @@ class Person < Profile | @@ -94,7 +94,6 @@ class Person < Profile | ||
| 94 | has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article | 94 | has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article |
| 95 | has_many :friendships, :dependent => :destroy | 95 | has_many :friendships, :dependent => :destroy |
| 96 | has_many :friends, :class_name => 'Person', :through => :friendships | 96 | has_many :friends, :class_name => 'Person', :through => :friendships |
| 97 | - has_many :owned_circles, as: :owner, :class_name => 'Circle' | ||
| 98 | 97 | ||
| 99 | scope :online, -> { | 98 | scope :online, -> { |
| 100 | joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes) | 99 | joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes) |
app/models/profile.rb
| @@ -235,9 +235,6 @@ class Profile < ApplicationRecord | @@ -235,9 +235,6 @@ class Profile < ApplicationRecord | ||
| 235 | 235 | ||
| 236 | has_many :email_templates, :foreign_key => :owner_id | 236 | has_many :email_templates, :foreign_key => :owner_id |
| 237 | 237 | ||
| 238 | - has_many :profile_followers, :as => :profile | ||
| 239 | - has_many :circles, :through => :profile_followers | ||
| 240 | - | ||
| 241 | # has_many :followers, -> { uniq }, :through => :profile_followers, :source => :person | 238 | # has_many :followers, -> { uniq }, :through => :profile_followers, :source => :person |
| 242 | 239 | ||
| 243 | # Although this should be a has_one relation, there are no non-silly names for | 240 | # Although this should be a has_one relation, there are no non-silly names for |