Module: Collavre::Creative::Linkable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Collavre::Creative
- Defined in:
- app/models/collavre/creative/linkable.rb
Instance Method Summary collapse
-
#create_linked_creative_for_user(user) ⇒ Object
공유 대상 사용자를 위해 Linked Creative를 생성합니다.
-
#effective_attribute(attr, visited_ids = Set.new) ⇒ Object
Returns the effective attribute for linked creatives.
- #effective_origin(visited_ids = Set.new) ⇒ Object
- #linked_children ⇒ Object
- #progress ⇒ Object
- #user ⇒ Object
Instance Method Details
#create_linked_creative_for_user(user) ⇒ Object
공유 대상 사용자를 위해 Linked Creative를 생성합니다.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/collavre/creative/linkable.rb', line 47 def create_linked_creative_for_user(user) original = effective_origin(Set.new) return if original.user_id == user.id ancestor_ids = original.ancestors.pluck(:id) has_ancestor_share = CreativeShare.where(creative_id: ancestor_ids, user_id: user.id) .where.not(permission: :no_access) .exists? has_owning_ancestors = Creative.where(id: ancestor_ids, user_id: user.id) .exists? return if has_ancestor_share or has_owning_ancestors Creative.find_or_create_by!(origin_id: original.id, user_id: user.id) do |c| c.parent_id = nil end end |
#effective_attribute(attr, visited_ids = Set.new) ⇒ Object
Returns the effective attribute for linked creatives
15 16 17 18 19 20 21 |
# File 'app/models/collavre/creative/linkable.rb', line 15 def effective_attribute(attr, visited_ids = Set.new) return self[attr] if origin_id.nil? || attr.to_s == "parent_id" return self[attr] if visited_ids.include?(id) visited_ids.add(id) origin.effective_attribute(attr, visited_ids) end |
#effective_origin(visited_ids = Set.new) ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/models/collavre/creative/linkable.rb', line 23 def effective_origin(visited_ids = Set.new) return self if origin_id.nil? return self if visited_ids.include?(id) visited_ids.add(id) origin.effective_origin(visited_ids) end |
#linked_children ⇒ Object
31 32 33 |
# File 'app/models/collavre/creative/linkable.rb', line 31 def linked_children origin_id.nil? ? (Collavre.current_user, :read) : origin&.(Collavre.current_user, :read) || [] end |
#progress ⇒ Object
35 36 37 |
# File 'app/models/collavre/creative/linkable.rb', line 35 def progress effective_attribute(:progress, Set.new) end |
#user ⇒ Object
39 40 41 42 43 44 |
# File 'app/models/collavre/creative/linkable.rb', line 39 def user target = effective_origin(Set.new) return super if target == self target.user end |