Class: Strain::SchemaTools::Defaults

Inherits:
Object
  • Object
show all
Defined in:
lib/strain/schema_tools/defaults.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_hash, data_hash) ⇒ Defaults

Returns a new instance of Defaults.



5
6
7
8
# File 'lib/strain/schema_tools/defaults.rb', line 5

def initialize(schema_hash, data_hash)
  @schema = schema_hash
  @data = data_hash
end

Instance Method Details

#data_with_defaultsObject



15
16
17
# File 'lib/strain/schema_tools/defaults.rb', line 15

def data_with_defaults
  merge_defaults(@data, default_values)
end

#default_valuesObject



10
11
12
13
# File 'lib/strain/schema_tools/defaults.rb', line 10

def default_values
  raise "Invalid schema." unless @schema["type"] == "object" && @schema.has_key?("properties")
  property_defaults(@schema["properties"])
end