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.



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

def options
  @options
end

#valueObject Also known as: name

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

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



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

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

#rawObject



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

def raw
  [value, options]
end

#volatile?Boolean

Returns:

  • (Boolean)


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

def volatile?
  @volatile || false
end