Module: Fleck::Core::Consumer::Decorators::ClassMethods

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#action(name, description = nil) ⇒ Object



43
44
45
46
# File 'lib/fleck/core/consumer/decorators.rb', line 43

def action(name, description = nil)
  action_name(name)
  desc(description)
end

#default_method_optionsObject



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

def default_method_options
  {
    action_name: nil,
    description: nil,
    params: {}.to_hash_with_indifferent_access,
    headers: {}.to_hash_with_indifferent_access
  }
end

#desc(description) ⇒ Object



48
49
50
# File 'lib/fleck/core/consumer/decorators.rb', line 48

def desc(description)
  method_options[:description] = description if description
end

#header(name, modifier = nil, **options) ⇒ Object



56
57
58
59
# File 'lib/fleck/core/consumer/decorators.rb', line 56

def header(name, modifier = nil, **options)
  raise 'Not Implemented'
  # method_options[:headers][name] = ActionParam.new(name, options[:type], options)
end

#method_added(name) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/fleck/core/consumer/decorators.rb', line 16

def method_added(name)
  super(name)

  # Register method as action `action` or `action_name` decorator has been used
  method_options[:action_name] && register_action(method_options[:action_name], name, method_options)

  # Reset method options after method has been added
  reset_method_options!
end

#method_optionsObject



26
27
28
# File 'lib/fleck/core/consumer/decorators.rb', line 26

def method_options
  @method_options ||= default_method_options
end

#param(name, modifier = nil, **options) ⇒ Object



52
53
54
# File 'lib/fleck/core/consumer/decorators.rb', line 52

def param(name, modifier = nil, **options)
  method_options[:params][name] = ActionParam.new(name, modifier, **options)
end

#reset_method_options!Object



39
40
41
# File 'lib/fleck/core/consumer/decorators.rb', line 39

def reset_method_options!
  @method_options = nil
end