Class: Pastore::Params::ActionParam

Inherits:
Object
  • Object
show all
Defined in:
lib/pastore/params/action_param.rb

Overview

Stores data about action parameters

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options) ⇒ ActionParam

Returns a new instance of ActionParam.



17
18
19
20
21
22
23
24
25
26
# File 'lib/pastore/params/action_param.rb', line 17

def initialize(name, **options)
  @name = name
  @options = options
  @scope = [@options&.fetch(:scope, nil)].flatten.compact
  @array = @options&.fetch(:array, false) == true
  @modifier = @options&.fetch(:modifier, nil)
  @type = @options&.fetch(:type, :any)

  check_options!
end

Instance Attribute Details

#modifierObject (readonly)

Returns the value of attribute modifier.



15
16
17
# File 'lib/pastore/params/action_param.rb', line 15

def modifier
  @modifier
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/pastore/params/action_param.rb', line 15

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/pastore/params/action_param.rb', line 15

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



15
16
17
# File 'lib/pastore/params/action_param.rb', line 15

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/pastore/params/action_param.rb', line 15

def type
  @type
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pastore/params/action_param.rb', line 32

def array?
  @array
end

#name_with_scopeObject



36
37
38
# File 'lib/pastore/params/action_param.rb', line 36

def name_with_scope
  [@scope, name].flatten.compact.join('.')
end

#validate(value) ⇒ Object



28
29
30
# File 'lib/pastore/params/action_param.rb', line 28

def validate(value)
  Pastore::Params::Validation.validate!(name, type, value, modifier, **options)
end