Class: Fleck::Core::Consumer::ActionParam

Inherits:
Object
  • Object
show all
Defined in:
lib/fleck/core/consumer/action_param.rb

Overview

Stores data about an action parameter, which will be used for automatic parameters validation.

Constant Summary collapse

AVAILABLE_TYPES =
%w[string number boolean object array].freeze
TYPE_ALIASES =
{
  'text' => 'string',
  'integer' => 'number',
  'float' => 'number',
  'hash' => 'object'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ ActionParam

Returns a new instance of ActionParam.



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

def initialize(name, type, options = {})
  @name = name
  @type = type
  @options = options

  check_options!
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/fleck/core/consumer/action_param.rb', line 16

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/fleck/core/consumer/action_param.rb', line 16

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/fleck/core/consumer/action_param.rb', line 16

def type
  @type
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/fleck/core/consumer/action_param.rb', line 30

def required?
  options[:required]
end

#string?Boolean

Returns:

  • (Boolean)


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

def string?
  @type == 'string'
end

#validate(value) ⇒ Object



34
35
36
# File 'lib/fleck/core/consumer/action_param.rb', line 34

def validate(value)
  Validation.new(name, type, value, options)
end