Class: JSON::SchemaBuilder::Schema
- Inherits:
-
Object
- Object
- JSON::SchemaBuilder::Schema
- Defined in:
- lib/json/schema_builder/schema.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #_deep_merge(this, other) ⇒ Object
-
#initialize(hash = {}) ⇒ Schema
constructor
A new instance of Schema.
- #merge(schema) ⇒ Object
- #merge!(schema) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Schema
Returns a new instance of Schema.
7 8 9 |
# File 'lib/json/schema_builder/schema.rb', line 7 def initialize(hash = {}) @data = hash.with_indifferent_access end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/json/schema_builder/schema.rb', line 4 def data @data end |
Instance Method Details
#_deep_merge(this, other) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/json/schema_builder/schema.rb', line 20 def _deep_merge(this, other) this.deep_merge(other) do |current_key, this_value, other_value| if this_value.is_a?(::Array) && other_value.is_a?(::Array) this_value + other_value else other_value end end end |
#merge(schema) ⇒ Object
11 12 13 |
# File 'lib/json/schema_builder/schema.rb', line 11 def merge(schema) self.class.new _deep_merge(data, schema.data) end |
#merge!(schema) ⇒ Object
15 16 17 18 |
# File 'lib/json/schema_builder/schema.rb', line 15 def merge!(schema) @data = _deep_merge(data, schema.data) self end |