Class: Render::HashAttribute
- Defined in:
- lib/render/attributes/hash_attribute.rb
Constant Summary
Constants inherited from Attribute
Instance Attribute Summary collapse
-
#required ⇒ Object
Returns the value of attribute required.
Attributes inherited from Attribute
#default, #enums, #exclusive_maximum, #exclusive_minimum, #format, #max_length, #maximum, #min_length, #minimum, #multiple_of, #name, #schema, #types
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ HashAttribute
constructor
A new instance of HashAttribute.
- #initialize_schema!(options) ⇒ Object
- #serialize(explicit_value, maintain_nil = false) ⇒ Object
Methods inherited from Attribute
#bias_type, #default_value, #nested_schema?
Constructor Details
#initialize(options = {}) ⇒ HashAttribute
Returns a new instance of HashAttribute.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/render/attributes/hash_attribute.rb', line 8 def initialize( = {}) super self.name = .keys.first = [name] () self.required = !![:required] initialize_schema!() if nested_schema?() end |
Instance Attribute Details
#required ⇒ Object
Returns the value of attribute required.
6 7 8 |
# File 'lib/render/attributes/hash_attribute.rb', line 6 def required @required end |
Instance Method Details
#initialize_schema!(options) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/render/attributes/hash_attribute.rb', line 20 def initialize_schema!() = { title: name, type: bias_type } self.schema = Schema.new(.merge()) end |
#serialize(explicit_value, maintain_nil = false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/render/attributes/hash_attribute.rb', line 29 def serialize(explicit_value, maintain_nil = false) if !!schema value = schema.serialize!(explicit_value) { name.to_sym => value } else if (maintain_nil && !explicit_value) value = explicit_value else value = (explicit_value || default_value) end { name.to_sym => Type.to(types, value) } end end |