Module: Fleck::Core::Consumer::Actions::ClassMethods

Defined in:
lib/fleck/core/consumer/actions.rb

Overview

Defines class methods to import when ‘Actions` module is imported.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actions_mapObject

Returns the value of attribute actions_map.



17
18
19
# File 'lib/fleck/core/consumer/actions.rb', line 17

def actions_map
  @actions_map
end

Instance Method Details

#actions(*args) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/fleck/core/consumer/actions.rb', line 19

def actions(*args)
  args.each do |item|
    case item
    when Hash then item.each { |k, v| register_action(k.to_s, v.to_s) }
    else register_action(item.to_s, item.to_s)
    end
  end
end

#register_action(action, method_name, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/fleck/core/consumer/actions.rb', line 28

def register_action(action, method_name, options = {})
  if Fleck::Consumer.instance_methods.include?(method_name.to_s.to_sym)
    raise ArgumentError, "Cannot use `:#{method_name}` method as an action, " \
                          'because it is reserved for Fleck::Consumer internal stuff!'
  end

  options[:method_name] = method_name.to_s
  options[:params] ||= {}
  actions_map[action.to_s] = options
end