Class: Lacerda::ObjectDescription
- Inherits:
-
Object
- Object
- Lacerda::ObjectDescription
- Defined in:
- lib/lacerda/object_description.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(defined_in_service, scoped_name, schema) ⇒ ObjectDescription
constructor
A new instance of ObjectDescription.
- #validate_data(data) ⇒ Object
- #validate_data!(data) ⇒ Object
Constructor Details
#initialize(defined_in_service, scoped_name, schema) ⇒ ObjectDescription
Returns a new instance of ObjectDescription.
23 24 25 26 27 28 29 |
# File 'lib/lacerda/object_description.rb', line 23 def initialize(defined_in_service, scoped_name, schema) @defined_in_service = defined_in_service @scoped_name = scoped_name @name = remove_service_from_scoped_name(scoped_name) @schema = schema.with_indifferent_access @schema['$schema'] ||= 'http://json-schema.org/draft-04/schema#' end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/lacerda/object_description.rb', line 22 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
22 23 24 |
# File 'lib/lacerda/object_description.rb', line 22 def schema @schema end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
22 23 24 |
# File 'lib/lacerda/object_description.rb', line 22 def service @service end |
Instance Method Details
#validate_data(data) ⇒ Object
35 36 37 38 39 |
# File 'lib/lacerda/object_description.rb', line 35 def validate_data(data) JSON::Validator.validate!(@schema, data) rescue JSON::Schema::ValidationError false end |
#validate_data!(data) ⇒ Object
31 32 33 |
# File 'lib/lacerda/object_description.rb', line 31 def validate_data!(data) JSON::Validator.validate!(@schema, data) end |