Module: Shared::IsData::Pinnable

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/shared/is_data/pinnable.rb

Overview

Shared code pinning objects (adding them to your pinboard).

Instance Method Summary collapse

Instance Method Details

#inserted?(user) ⇒ Boolean

Returns true if this item is set to be inserted.

Returns:

  • (Boolean)

    true if this item is set to be inserted



37
38
39
# File 'app/models/concerns/shared/is_data/pinnable.rb', line 37

def inserted?(user)
  pinboard_item_for(user).try(:is_inserted)
end

#pinboard_item_for(user) ⇒ PinboardItem?

Returns the pinboard item corresponding to the object, if present.

Returns:

  • (PinboardItem, nil)

    the pinboard item corresponding to the object, if present



26
27
28
29
30
31
32
33
# File 'app/models/concerns/shared/is_data/pinnable.rb', line 26

def pinboard_item_for(user)
  return nil unless user
  if pinboard_items.loaded?
    pinboard_items.detect { |i| i.user_id == user.id }
  else
    pinboard_items.where(user_id: user.id).for_object(self.metamorphosize).first
  end
end

#pinned?(user, project_id) ⇒ Boolean

Returns whether the object is pinned by the user.

Returns:

  • (Boolean)

    whether the object is pinned by the user



16
17
18
19
20
21
22
# File 'app/models/concerns/shared/is_data/pinnable.rb', line 16

def pinned?(user, project_id)
  if pinboard_items.loaded?
    !!pinboard_items.detect { |i| i.project_id == project_id && i.user_id == user.id }
  else
    user && user.pinboard_items.where(project_id:).for_object(self.metamorphosize).any?
  end
end