Class: Dynflow::Coordinator::Record

Inherits:
Serializable show all
Includes:
Algebrick::TypeCheck
Defined in:
lib/dynflow/coordinator.rb

Direct Known Subclasses

Lock, WorldRecord

Constant Summary

Constants inherited from Serializable

Serializable::LEGACY_TIME_FORMAT, Serializable::TIME_FORMAT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Serializable

from_hash

Constructor Details

#initialize(*args) ⇒ Record

Returns a new instance of Record.



43
44
45
46
# File 'lib/dynflow/coordinator.rb', line 43

def initialize(*args)
  @data = {}
  @data = Utils.indifferent_hash(@data.merge(class: self.class.name))
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



28
29
30
# File 'lib/dynflow/coordinator.rb', line 28

def data
  @data
end

Class Method Details

.constantize(name) ⇒ Object



36
37
38
39
40
41
# File 'lib/dynflow/coordinator.rb', line 36

def self.constantize(name)
  Serializable.constantize(name)
rescue NameError
  # If we don't find the lock name, return the most generic version
  Record
end

.new_from_hash(hash) ⇒ Object



32
33
34
# File 'lib/dynflow/coordinator.rb', line 32

def self.new_from_hash(hash)
  self.allocate.tap { |record| record.from_hash(hash) }
end

Instance Method Details

#==(other_object) ⇒ Object



74
75
76
# File 'lib/dynflow/coordinator.rb', line 74

def ==(other_object)
  self.class == other_object.class && self.id == other_object.id
end

#from_hash(hash) ⇒ Object



48
49
50
51
# File 'lib/dynflow/coordinator.rb', line 48

def from_hash(hash)
  @data      = hash
  @from_hash = true
end

#hashObject



78
79
80
# File 'lib/dynflow/coordinator.rb', line 78

def hash
  [self.class, self.id].hash
end

#idObject



57
58
59
# File 'lib/dynflow/coordinator.rb', line 57

def id
  @data[:id]
end

#to_hashObject



53
54
55
# File 'lib/dynflow/coordinator.rb', line 53

def to_hash
  @data
end

#to_sObject



70
71
72
# File 'lib/dynflow/coordinator.rb', line 70

def to_s
  "#{self.class.name}: #{id}"
end

#validate!Object

check to be performed before we try to acquire the lock



63
64
65
66
67
68
# File 'lib/dynflow/coordinator.rb', line 63

def validate!
  Type! id,    String
  Type! @data, Hash
  raise "The record id %{s} too large" % id if id.size > 100
  raise "The record class name %{s} too large" % self.class.name if self.class.name.size > 100
end