Class: Spree::Admin::Actions::Action
- Inherits:
-
Object
- Object
- Spree::Admin::Actions::Action
- Defined in:
- app/models/spree/admin/actions/action.rb
Constant Summary collapse
- STYLE_CLASSES =
{ ::Spree::Admin::Actions::ActionStyle::PRIMARY => 'btn-primary', ::Spree::Admin::Actions::ActionStyle::SECONDARY => 'btn-secondary', ::Spree::Admin::Actions::ActionStyle::LIGHT => 'btn-light' }
Instance Attribute Summary collapse
-
#data_attributes ⇒ Object
readonly
Returns the value of attribute data_attributes.
-
#icon_key ⇒ Object
readonly
Returns the value of attribute icon_key.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#label_translation_key ⇒ Object
readonly
Returns the value of attribute label_translation_key.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #available?(current_ability, resource = nil) ⇒ Boolean
- #classes ⇒ Object
-
#initialize(key, label_translation_key, url, icon_key, style, availability_checks, additional_classes, method, id, target, data_attributes) ⇒ Action
constructor
rubocop:disable Metrics/ParameterLists.
- #url(resource = nil) ⇒ Object
Constructor Details
#initialize(key, label_translation_key, url, icon_key, style, availability_checks, additional_classes, method, id, target, data_attributes) ⇒ Action
rubocop:disable Metrics/ParameterLists
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/spree/admin/actions/action.rb', line 13 def initialize(key, label_translation_key, url, icon_key, style, availability_checks, additional_classes, method, id, target, data_attributes) # rubocop:disable Metrics/ParameterLists @key = key @label_translation_key = label_translation_key @url = url @icon_key = icon_key @style = style @availability_checks = availability_checks @additional_classes = additional_classes @method = method @id = id @target = target @data_attributes = data_attributes end |
Instance Attribute Details
#data_attributes ⇒ Object (readonly)
Returns the value of attribute data_attributes.
11 12 13 |
# File 'app/models/spree/admin/actions/action.rb', line 11 def data_attributes @data_attributes end |
#icon_key ⇒ Object (readonly)
Returns the value of attribute icon_key.
11 12 13 |
# File 'app/models/spree/admin/actions/action.rb', line 11 def icon_key @icon_key end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'app/models/spree/admin/actions/action.rb', line 11 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'app/models/spree/admin/actions/action.rb', line 11 def key @key end |
#label_translation_key ⇒ Object (readonly)
Returns the value of attribute label_translation_key.
11 12 13 |
# File 'app/models/spree/admin/actions/action.rb', line 11 def label_translation_key @label_translation_key end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
11 12 13 |
# File 'app/models/spree/admin/actions/action.rb', line 11 def method @method end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
11 12 13 |
# File 'app/models/spree/admin/actions/action.rb', line 11 def target @target end |
Instance Method Details
#available?(current_ability, resource = nil) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'app/models/spree/admin/actions/action.rb', line 27 def available?(current_ability, resource = nil) return true if @availability_checks.empty? result = @availability_checks.map { |check| check.call(current_ability, resource) } result.all?(true) end |
#classes ⇒ Object
39 40 41 42 43 44 |
# File 'app/models/spree/admin/actions/action.rb', line 39 def classes [ STYLE_CLASSES[@style], @additional_classes ].compact.join(' ') end |
#url(resource = nil) ⇒ Object
35 36 37 |
# File 'app/models/spree/admin/actions/action.rb', line 35 def url(resource = nil) @url.is_a?(Proc) ? @url.call(resource) : @url end |