Module: SimpleAMS::Options::Concerns::ValueHash

Included in:
Adapter, PrimaryId, Type
Defined in:
lib/simple_ams/options/concerns/value_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 6

def options
  @options
end

#valueObject Also known as: name

Returns the value of attribute value.



6
7
8
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 6

def value
  @value
end

Instance Method Details

#initialize(value, options = {}, resource:, serializer:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 9

def initialize(value, options = {}, resource:, serializer:)
  if value.respond_to?(:call)
    @volatile = true
    _value = value.call(resource, serializer)
    if _value.is_a?(Array) && _value.length > 1
      @value = _value[0]
      @options = (_value[-1] || {}).merge(options || {})
    else
      @value = _value
      @options = options || {}
    end
  else
    @value = value.is_a?(String) ? value.to_sym : value
    @options = options || {}
  end
end

#rawObject



26
27
28
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 26

def raw
  [value, options]
end

#volatile?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 30

def volatile?
  return @volatile || false
end