Module: Dryv::Schema

Defined in:
lib/dryv/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object (private)



144
145
146
# File 'lib/dryv/schema.rb', line 144

def method_missing(method)
  attributes[method.to_sym]
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/dryv/schema.rb', line 5

def attributes
  @attributes
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/dryv/schema.rb', line 5

def errors
  @errors
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/dryv/schema.rb', line 14

def [](key)
  attributes[key.to_sym]
end

#initialize(params) ⇒ Object



7
8
9
10
11
# File 'lib/dryv/schema.rb', line 7

def initialize(params)
  @errors     = Dryv::Errors.new
  @attributes = cast({ wrap: params }.deep_symbolize_keys[:wrap], schema)
  JSON::Validator.validate!(schema, attributes)
end

#schemaObject

Raises:

  • (NotImplemented)


26
27
28
# File 'lib/dryv/schema.rb', line 26

def schema
  raise NotImplemented
end

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/dryv/schema.rb', line 19

def valid?
  validate_attributes(attributes, schema)
  validate_additional
  !errors.any?
end