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



43
44
45
# File 'app/models/concerns/shared/is_data/pinnable.rb', line 43

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



29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/concerns/shared/is_data/pinnable.rb', line 29

def pinboard_item_for(user)
  return nil unless user
  if pinboard_items.loaded?
    pinboard_items.each do |i|
      return i if pinboard_item.user_id = user.id  # i.project_id == project_id && i.user_id == user.id
    end
    return nil
  else
    return 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
23
24
25
# File 'app/models/concerns/shared/is_data/pinnable.rb', line 16

def pinned?(user, project_id)
  if pinboard_items.loaded?
    pinboard_items.each do |i|
      return true if i.project_id == project_id && i.user_id == user.id
    end
    return false
  else
    user && user.pinboard_items.where(project_id: project_id).for_object(self.metamorphosize).any?
  end
end