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를 생성합니다.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/collavre/creative/linkable.rb', line 56 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
24 25 26 27 28 29 30 |
# File 'app/models/collavre/creative/linkable.rb', line 24 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
32 33 34 35 36 37 38 |
# File 'app/models/collavre/creative/linkable.rb', line 32 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
40 41 42 |
# File 'app/models/collavre/creative/linkable.rb', line 40 def linked_children origin_id.nil? ? (Collavre.current_user, :read) : origin&.(Collavre.current_user, :read) || [] end |
#progress ⇒ Object
44 45 46 |
# File 'app/models/collavre/creative/linkable.rb', line 44 def progress effective_attribute(:progress, Set.new) end |
#user ⇒ Object
48 49 50 51 52 53 |
# File 'app/models/collavre/creative/linkable.rb', line 48 def user target = effective_origin(Set.new) return super if target == self target.user end |