Class: Dynflow::Coordinator::Record
- Inherits:
-
Serializable
show all
- Includes:
- Algebrick::TypeCheck
- Defined in:
- lib/dynflow/coordinator.rb
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
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
#data ⇒ Object
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
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
|
#hash ⇒ Object
78
79
80
|
# File 'lib/dynflow/coordinator.rb', line 78
def hash
[self.class, self.id].hash
end
|
#id ⇒ Object
57
58
59
|
# File 'lib/dynflow/coordinator.rb', line 57
def id
@data[:id]
end
|
#to_hash ⇒ Object
53
54
55
|
# File 'lib/dynflow/coordinator.rb', line 53
def to_hash
@data
end
|
#to_s ⇒ Object
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
|