Class: JSON::SchemaBuilder::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/json/schema_builder/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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