Class: Reviewable::Actions
- Inherits:
-
Collection
- Object
- Collection
- Reviewable::Actions
- Defined in:
- lib/reviewable/actions.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#bundles ⇒ Object
readonly
Returns the value of attribute bundles.
-
#reviewable ⇒ Object
readonly
Returns the value of attribute reviewable.
Class Method Summary collapse
-
.common_actions ⇒ Object
Add common actions here to make them easier for reviewables to re-use.
Instance Method Summary collapse
- #add(id, bundle: nil) {|action| ... } ⇒ Object
- #add_bundle(id, icon: nil, label: nil) ⇒ Object
-
#initialize(reviewable, guardian, args = nil) ⇒ Actions
constructor
A new instance of Actions.
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
#bundles ⇒ Object (readonly)
Returns the value of attribute bundles.
7 8 9 |
# File 'lib/reviewable/actions.rb', line 7 def bundles @bundles end |
#reviewable ⇒ Object (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_actions ⇒ Object
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
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 |