Module: SimpleAMS::Options::Concerns::ValueHash
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
(also: #name)
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #initialize(value, options = {}, resource:, serializer:) ⇒ Object
- #raw ⇒ Object
- #volatile? ⇒ Boolean
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 5 def @options end |
#value ⇒ Object 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, = {}, 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( || {}) else @value = computed_value @options = || {} end else @value = value.is_a?(String) ? value.to_sym : value @options = || {} end end |
#raw ⇒ Object
25 26 27 |
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 25 def raw [value, ] end |
#volatile? ⇒ Boolean
29 30 31 |
# File 'lib/simple_ams/options/concerns/value_hash.rb', line 29 def volatile? @volatile || false end |