Commit 51cb598ffd8665e20ac3f53a8b61da66fcc52d6b

Authored by Gabriel Silva
1 parent a4dae44e

Moves relations to concerns

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
app/models/concerns/followable.rb
1 1 module Followable
2 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 9 def followers
5 10 person_followers = Person.joins(:owned_circles).merge(circles).uniq
6 11 external_person_followers = ExternalPerson.joins(:owned_circles).merge(circles).uniq
... ...
app/models/concerns/follower.rb
1 1 module Follower
2 2 extend ActiveSupport::Concern
3 3  
  4 + included do
  5 + has_many :owned_circles, as: :owner, :class_name => "Circle"
  6 + end
  7 +
4 8 def follow(profile, circles)
5 9 circles = [circles] unless circles.is_a?(Array)
6 10 circles.each do |new_circle|
... ...
app/models/external_person.rb
... ... @@ -5,10 +5,7 @@ class ExternalPerson &lt; ExternalProfile
5 5 include ProfileEntity
6 6 include Follower
7 7  
8   - has_many :owned_circles, as: :owner, :class_name => "Circle"
9   -
10 8 validates_uniqueness_of :identifier, scope: :source
11   -
12 9 validates_presence_of :source, :email, :created_at
13 10  
14 11 attr_accessible :source, :email, :created_at
... ...
app/models/external_profile.rb
... ... @@ -2,9 +2,6 @@ class ExternalProfile &lt; ActiveRecord::Base
2 2  
3 3 include Followable
4 4  
5   - has_many :profile_followers, :as => :profile
6   - has_many :circles, :through => :profile_followers
7   -
8 5 def name
9 6 "#{self[:name]}@#{self.source}"
10 7 end
... ...
app/models/person.rb
... ... @@ -94,7 +94,6 @@ class Person &lt; Profile
94 94 has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article
95 95 has_many :friendships, :dependent => :destroy
96 96 has_many :friends, :class_name => 'Person', :through => :friendships
97   - has_many :owned_circles, as: :owner, :class_name => 'Circle'
98 97  
99 98 scope :online, -> {
100 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 &lt; ApplicationRecord
235 235  
236 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 238 # has_many :followers, -> { uniq }, :through => :profile_followers, :source => :person
242 239  
243 240 # Although this should be a has_one relation, there are no non-silly names for
... ...