Module: SimpleAMS::Options::Concerns::NameValueHash
- Included in:
- Forms::Form, Generics::Option, Links::Link, Metas::Meta
- Defined in:
- lib/simple_ams/options/concerns/name_value_hash.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #initialize(name, value, options = {}, resource:, serializer:) ⇒ Object
- #raw ⇒ Object
- #volatile? ⇒ Boolean
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/simple_ams/options/concerns/name_value_hash.rb', line 5 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_ams/options/concerns/name_value_hash.rb', line 5 def @options end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/simple_ams/options/concerns/name_value_hash.rb', line 5 def value @value end |
Instance Method Details
#initialize(name, value, options = {}, resource:, serializer:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/simple_ams/options/concerns/name_value_hash.rb', line 7 def initialize(name, value, = {}, resource:, serializer:) @name = name.is_a?(String) ? name.to_sym : name 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 @options = || {} end end |
#raw ⇒ Object
25 26 27 |
# File 'lib/simple_ams/options/concerns/name_value_hash.rb', line 25 def raw [name, value, ] end |
#volatile? ⇒ Boolean
29 30 31 |
# File 'lib/simple_ams/options/concerns/name_value_hash.rb', line 29 def volatile? @volatile || false end |