Class: Fray::Data::Base

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/fray/data.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
# File 'lib/fray/data.rb', line 8

def initialize(hash)
  if JSON::Validator.validate(__schema, hash)
    super(JSON.parse(JSON.generate(hash)))
    self.freeze
  else
    e = "#{hash.inspect} failed schema validation:\n\n" +
        JSON::Validator.fully_validate(__schema, hash).join("\n")
    raise ArgumentError, e
  end
end