Class: Lacerda::ObjectDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/lacerda/object_description.rb

Direct Known Subclasses

ConsumedObject, PublishedObject

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/lacerda/object_description.rb', line 22

def name
  @name
end

#schemaObject (readonly)

Returns the value of attribute schema.



22
23
24
# File 'lib/lacerda/object_description.rb', line 22

def schema
  @schema
end

#serviceObject (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