Module: Dry::Schema
- Defined in:
- lib/dry/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
143
144
145
|
# File 'lib/dry/schema.rb', line 143
def method_missing(method)
attributes[method.to_sym]
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4
5
6
|
# File 'lib/dry/schema.rb', line 4
def attributes
@attributes
end
|
#errors ⇒ Object
Returns the value of attribute errors.
4
5
6
|
# File 'lib/dry/schema.rb', line 4
def errors
@errors
end
|
Instance Method Details
#[](key) ⇒ Object
13
14
15
|
# File 'lib/dry/schema.rb', line 13
def [](key)
attributes[key.to_sym]
end
|
#initialize(params) ⇒ Object
6
7
8
9
10
|
# File 'lib/dry/schema.rb', line 6
def initialize(params)
@errors = Dry::Errors.new
@attributes = cast({ wrap: params }.deep_symbolize_keys[:wrap], schema)
JSON::Validator.validate!(schema, attributes)
end
|
#schema ⇒ Object
25
26
27
|
# File 'lib/dry/schema.rb', line 25
def schema
raise NotImplemented
end
|
#valid? ⇒ Boolean
18
19
20
21
22
|
# File 'lib/dry/schema.rb', line 18
def valid?
validate_attributes(attributes, schema)
validate_additional
!errors.any?
end
|