change *_count methods to use delegate to save lines in map.rb model
This commit is contained in:
parent
8a3b4983d4
commit
ca7166c6bc
1 changed files with 7 additions and 18 deletions
|
@ -34,6 +34,13 @@ class Map < ApplicationRecord
|
||||||
|
|
||||||
after_save :update_deferring_topics_and_synapses, if: :permission_changed?
|
after_save :update_deferring_topics_and_synapses, if: :permission_changed?
|
||||||
|
|
||||||
|
delegate :count, to: :topics, prefix: :topic # same as `def topic_count; topics.count; end`
|
||||||
|
delegate :count, to: :synapses, prefix: :synapse
|
||||||
|
delegate :count, to: :contributors, prefix: :contributor
|
||||||
|
delegate :count, to: :stars, prefix: :star
|
||||||
|
|
||||||
|
delegate :name, to: :user, prefix: true
|
||||||
|
|
||||||
def mappings
|
def mappings
|
||||||
topicmappings.or(synapsemappings)
|
topicmappings.or(synapsemappings)
|
||||||
end
|
end
|
||||||
|
@ -46,28 +53,10 @@ class Map < ApplicationRecord
|
||||||
User.where(id: user_id).or(User.where(id: collaborators))
|
User.where(id: user_id).or(User.where(id: collaborators))
|
||||||
end
|
end
|
||||||
|
|
||||||
def topic_count
|
|
||||||
topics.length
|
|
||||||
end
|
|
||||||
|
|
||||||
def synapse_count
|
|
||||||
synapses.length
|
|
||||||
end
|
|
||||||
|
|
||||||
delegate :name, to: :user, prefix: true
|
|
||||||
|
|
||||||
def user_image
|
def user_image
|
||||||
user.image.url(:thirtytwo)
|
user.image.url(:thirtytwo)
|
||||||
end
|
end
|
||||||
|
|
||||||
def contributor_count
|
|
||||||
contributors.length
|
|
||||||
end
|
|
||||||
|
|
||||||
def star_count
|
|
||||||
stars.length
|
|
||||||
end
|
|
||||||
|
|
||||||
def collaborator_ids
|
def collaborator_ids
|
||||||
collaborators.map(&:id)
|
collaborators.map(&:id)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue