Class: Deimos::SchemaClass::Base
- Inherits:
-
Object
- Object
- Deimos::SchemaClass::Base
- Defined in:
- lib/deimos/schema_class/base.rb
Overview
Base Class for Schema Classes generated from Avro.
Class Method Summary collapse
-
.initialize_from_value(value) ⇒ Object
Initializes this class from a given value.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
- #[]=(key, val) ⇒ Object
-
#as_json(_opts = {}) ⇒ Hash
Converts the object to a hash which can be used for debugging or comparing objects.
-
#initialize(*_args) ⇒ Base
constructor
:nodoc:.
-
#merge(other_hash) ⇒ SchemaClasses::Base
Merge a hash or an identical schema object with this one and return a new object.
-
#to_h ⇒ Hash
Converts the object attributes to a hash which can be used for Kafka.
-
#to_json(*_args) ⇒ String
Converts the object to a string that represents a JSON object.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(*_args) ⇒ Base
:nodoc:
11 12 |
# File 'lib/deimos/schema_class/base.rb', line 11 def initialize(*_args) end |
Class Method Details
.initialize_from_value(value) ⇒ Object
Initializes this class from a given value
67 68 69 |
# File 'lib/deimos/schema_class/base.rb', line 67 def self.initialize_from_value(value) raise NotImplementedError end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
50 51 52 53 54 55 56 57 |
# File 'lib/deimos/schema_class/base.rb', line 50 def ==(other) comparison = other if other.class == self.class comparison = other.as_json end comparison == self.as_json end |
#[]=(key, val) ⇒ Object
34 35 36 |
# File 'lib/deimos/schema_class/base.rb', line 34 def []=(key, val) self.send("#{key}=", val) end |
#as_json(_opts = {}) ⇒ Hash
Converts the object to a hash which can be used for debugging or comparing objects.
22 23 24 |
# File 'lib/deimos/schema_class/base.rb', line 22 def as_json(_opts={}) JSON.parse(to_json) end |
#merge(other_hash) ⇒ SchemaClasses::Base
Merge a hash or an identical schema object with this one and return a new object.
41 42 43 44 45 46 47 |
# File 'lib/deimos/schema_class/base.rb', line 41 def merge(other_hash) obj = self.class.new(**self.to_h.symbolize_keys) other_hash.to_h.each do |k, v| obj.send("#{k}=", v) end obj end |
#to_h ⇒ Hash
Converts the object attributes to a hash which can be used for Kafka
28 29 30 |
# File 'lib/deimos/schema_class/base.rb', line 28 def to_h raise NotImplementedError end |
#to_json(*_args) ⇒ String
Converts the object to a string that represents a JSON object
16 17 18 |
# File 'lib/deimos/schema_class/base.rb', line 16 def to_json(*_args) to_h.to_json end |
#to_s ⇒ Object
:nodoc:
60 61 62 63 |
# File 'lib/deimos/schema_class/base.rb', line 60 def to_s klass = self.class "#{klass}(#{self.as_json.symbolize_keys.to_s[1..-2]})" end |