Module: Croods::Resource::Actions
- Defined in:
- lib/croods/resource/actions.rb
Constant Summary collapse
- DEFAULT_ACTIONS =
%i[index create update destroy show].freeze
Instance Method Summary collapse
- #actions(*names) ⇒ Object
- #add_action(name, method: :get, on: :member, &block) ⇒ Object
- #additional_actions ⇒ Object
- #default_actions ⇒ Object
- #filtered_actions ⇒ Object
- #ignored_actions ⇒ Object
- #skip_actions(*names) ⇒ Object (also: #skip_action)
Instance Method Details
#actions(*names) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/croods/resource/actions.rb', line 14 def actions(*names) return filtered_actions if names.empty? @actions = names.map do |name| Croods::Action.new name end end |
#add_action(name, method: :get, on: :member, &block) ⇒ Object
28 29 30 31 32 |
# File 'lib/croods/resource/actions.rb', line 28 def add_action(name, method: :get, on: :member, &block) additional_actions << Action.new( name, method: method, on: on, block: block ) end |
#additional_actions ⇒ Object
34 35 36 |
# File 'lib/croods/resource/actions.rb', line 34 def additional_actions @additional_actions ||= [] end |
#default_actions ⇒ Object
8 9 10 11 12 |
# File 'lib/croods/resource/actions.rb', line 8 def default_actions DEFAULT_ACTIONS.map do |name| Croods::Action.new name end end |
#filtered_actions ⇒ Object
22 23 24 25 26 |
# File 'lib/croods/resource/actions.rb', line 22 def filtered_actions @actions ||= default_actions @actions.reject { |action| ignored_actions.include?(action.name) } end |
#ignored_actions ⇒ Object
44 45 46 |
# File 'lib/croods/resource/actions.rb', line 44 def ignored_actions @ignored_actions ||= [] end |
#skip_actions(*names) ⇒ Object Also known as: skip_action
38 39 40 41 42 |
# File 'lib/croods/resource/actions.rb', line 38 def skip_actions(*names) names.each do |name| ignored_actions << name.to_sym end end |