Class: Reviewable::Actions

Inherits:
Collection show all
Defined in:
lib/reviewable/actions.rb

Defined Under Namespace

Classes: Action, Bundle

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Collection

#blank?, #each, #has?, #present?, #to_a

Constructor Details

#initialize(reviewable, guardian, args = nil) ⇒ Actions

Returns a new instance of Actions.



9
10
11
12
# File 'lib/reviewable/actions.rb', line 9

def initialize(reviewable, guardian, args = nil)
  super(reviewable, guardian, args)
  @bundles = []
end

Instance Attribute Details

#bundlesObject (readonly)

Returns the value of attribute bundles.



7
8
9
# File 'lib/reviewable/actions.rb', line 7

def bundles
  @bundles
end

#reviewableObject (readonly)

Returns the value of attribute reviewable.



7
8
9
# File 'lib/reviewable/actions.rb', line 7

def reviewable
  @reviewable
end

Class Method Details

.common_actionsObject

Add common actions here to make them easier for reviewables to re-use. If it’s a one off, add it manually.



16
17
18
19
20
21
22
# File 'lib/reviewable/actions.rb', line 16

def self.common_actions
  {
    approve: Action.new(:approve, "thumbs-up", "reviewables.actions.approve.title"),
    reject: Action.new(:reject, "thumbs-down", "reviewables.actions.reject.title"),
    delete: Action.new(:delete, "trash-alt", "reviewables.actions.delete_single.title"),
  }
end

Instance Method Details

#add(id, bundle: nil) {|action| ... } ⇒ Object

Yields:

  • (action)


61
62
63
64
65
66
67
68
69
# File 'lib/reviewable/actions.rb', line 61

def add(id, bundle: nil)
  id = [reviewable.target_type&.underscore, id].compact_blank.join("-")
  action = Actions.common_actions[id] || Action.new(id)
  yield action if block_given?
  @content << action

  bundle ||= add_bundle(id)
  bundle.actions << action
end

#add_bundle(id, icon: nil, label: nil) ⇒ Object



55
56
57
58
59
# File 'lib/reviewable/actions.rb', line 55

def add_bundle(id, icon: nil, label: nil)
  bundle = Bundle.new(id, icon: icon, label: label)
  @bundles << bundle
  bundle
end