Class: Deimos::SchemaClass::Record
- Defined in:
- lib/deimos/schema_class/record.rb
Overview
Base Class of Record Classes generated from Avro.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
Element access method as if this Object were a hash.
-
#as_json(_opts = {}) ⇒ Hash
Converts the object to a hash which can be used for debugging or comparing objects.
-
#full_schema ⇒ String
Returns the full schema name of the inheriting class.
-
#namespace ⇒ String
Returns the namespace for the schema of the inheriting class.
-
#schema ⇒ String
Returns the schema name of the inheriting class.
-
#schema_fields ⇒ Array<String>
An array of fields names in the schema.
-
#validator ⇒ Deimos::SchemaBackends::Base
Returns the schema validator from the schema backend.
-
#with_indifferent_access ⇒ Object
:nodoc.
Methods inherited from Base
#==, #[]=, #initialize, #merge, #to_h, #to_json, #to_s
Constructor Details
This class inherits a constructor from Deimos::SchemaClass::Base
Class Method Details
.initialize_from_value(value) ⇒ Object
:nodoc:
59 60 61 62 63 |
# File 'lib/deimos/schema_class/record.rb', line 59 def self.initialize_from_value(value) return nil if value.nil? value.is_a?(self) ? value : self.new(**value.symbolize_keys) end |
Instance Method Details
#[](key) ⇒ Object
Element access method as if this Object were a hash
20 21 22 |
# File 'lib/deimos/schema_class/record.rb', line 20 def [](key) self.try(key.to_sym) end |
#as_json(_opts = {}) ⇒ Hash
Converts the object to a hash which can be used for debugging or comparing objects.
13 14 15 |
# File 'lib/deimos/schema_class/record.rb', line 13 def as_json(_opts={}) super.except('payload_key') end |
#full_schema ⇒ String
Returns the full schema name of the inheriting class.
43 44 45 |
# File 'lib/deimos/schema_class/record.rb', line 43 def full_schema "#{namespace}.#{schema}" end |
#namespace ⇒ String
Returns the namespace for the schema of the inheriting class.
37 38 39 |
# File 'lib/deimos/schema_class/record.rb', line 37 def namespace raise NotImplementedError end |
#schema ⇒ String
Returns the schema name of the inheriting class.
31 32 33 |
# File 'lib/deimos/schema_class/record.rb', line 31 def schema raise NotImplementedError end |
#schema_fields ⇒ Array<String>
Returns an array of fields names in the schema.
54 55 56 |
# File 'lib/deimos/schema_class/record.rb', line 54 def schema_fields validator.schema_fields.map(&:name) end |
#validator ⇒ Deimos::SchemaBackends::Base
Returns the schema validator from the schema backend
49 50 51 |
# File 'lib/deimos/schema_class/record.rb', line 49 def validator Deimos.schema_backend(schema: schema, namespace: namespace) end |
#with_indifferent_access ⇒ Object
:nodoc
25 26 27 |
# File 'lib/deimos/schema_class/record.rb', line 25 def with_indifferent_access self end |