Module: Gearhead::Extensions::CustomActions

Included in:
Gear
Defined in:
lib/gearhead/extensions/custom_actions.rb

Defined Under Namespace

Classes: CustomAction

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
# File 'lib/gearhead/extensions/custom_actions.rb', line 4

def self.included(klass)
  klass.define_gear_setting :collection_actions, {}
  klass.define_gear_setting :member_actions, {}
end

Instance Method Details

#collection_action(name, options = {}, &block) ⇒ Object



31
32
33
# File 'lib/gearhead/extensions/custom_actions.rb', line 31

def collection_action(name, options = {}, &block)
  custom_action(:collection, name, options, &block)
end

#custom_action(type, name, options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/gearhead/extensions/custom_actions.rb', line 18

def custom_action(type, name, options = {}, &block)
  vias = (Array(options[:via]).presence || [:get]).map { |via| via.downcase.to_sym }
  if type == :member
    @_gear_member_actions[name] = CustomAction.new(name, vias, &block)
  else
    @_gear_collection_actions[name] = CustomAction.new(name, vias, &block)
  end
end

#member_action(name, options = {}, &block) ⇒ Object



27
28
29
# File 'lib/gearhead/extensions/custom_actions.rb', line 27

def member_action(name, options = {}, &block)
  custom_action(:member, name, options, &block)
end