Module: Yoda::Store::Objects::Serializable

Included in:
Base, LibrariesStatus, Library::Core, Library::Gem, Library::Std, SerializableSet
Defined in:
lib/yoda/store/objects/serializable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



16
17
18
# File 'lib/yoda/store/objects/serializable.rb', line 16

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#==(another) ⇒ Object



44
45
46
# File 'lib/yoda/store/objects/serializable.rb', line 44

def ==(another)
  eql?(another)
end

#derive(params = {}) ⇒ Object

Create a new instance which has the original parameters and overrided parameters.

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    parameters to override



33
34
35
# File 'lib/yoda/store/objects/serializable.rb', line 33

def derive(params = {})
  self.class.new(**to_h.merge(params))
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/yoda/store/objects/serializable.rb', line 37

def eql?(another)
  return object.eql?(another) if respond_to?(:object) && !object.respond_to?(:object)
  return eql?(another.object) if another.respond_to?(:object) && !another.object.respond_to?(:object)
  return false unless self.class.name == another.class.name
  to_h.eql?(another.to_h)
end

#hashObject



48
49
50
# File 'lib/yoda/store/objects/serializable.rb', line 48

def hash
  to_h.hash
end

#to_hHash

This method is abstract.

Returns:

  • (Hash)


22
23
24
# File 'lib/yoda/store/objects/serializable.rb', line 22

def to_h
  fail NotImplementedError
end

#to_json(*options) ⇒ String

Returns:

  • (String)


27
28
29
# File 'lib/yoda/store/objects/serializable.rb', line 27

def to_json(*options)
  to_h.merge(json_class: self.class.name).to_json
end