Class: Flor::FlorModel
- Inherits:
-
Object
show all
- Defined in:
- lib/flor/unit/models.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.unit ⇒ Object
Returns the value of attribute unit.
34
35
36
|
# File 'lib/flor/unit/models.rb', line 34
def unit
@unit
end
|
Class Method Details
.from_h(h) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/flor/unit/models.rb', line 104
def from_h(h)
cols = columns
h
.inject({}) { |r, (k, v)|
k = k.to_sym
if k == :data
r[:content] = Flor.to_blob(v)
elsif cols.include?(k)
r[k] = v
end
r }
end
|
Instance Method Details
#data(cache = true) ⇒ Object
68
69
70
71
|
# File 'lib/flor/unit/models.rb', line 68
def data(cache=true)
cache ? (@flor_model_cache_data = _data) : _data
end
|
#execution(reload = false) ⇒ Object
Return a Flor::Execution instance linked to this model
42
43
44
45
46
47
48
49
|
# File 'lib/flor/unit/models.rb', line 42
def execution(reload=false)
exid = @values[:exid]; return nil unless exid
@flor_model_cache_execution = nil if reload
@flor_model_cache_execution ||= unit.executions[exid: exid]
end
|
#node(reload = false) ⇒ Object
Returns the node hash linked to this model
53
54
55
56
57
58
59
60
|
# File 'lib/flor/unit/models.rb', line 53
def node(reload=false)
nid = @values[:nid]; return nil unless nid
exe = execution(reload); return nil unless exe
nodes = exe.data['nodes']; return nil unless nodes
nodes[nid]
end
|
#payload(reload = false) ⇒ Object
62
63
64
65
66
|
# File 'lib/flor/unit/models.rb', line 62
def payload(reload=false)
nod = node(reload)
nod ? nod['payload'] : nil
end
|
#refresh ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/flor/unit/models.rb', line 73
def refresh
instance_variables
.each do |k|
instance_variable_set(k, nil) \
if k.to_s.start_with?('@flor_model_cache_')
end
super
end
|
#storage ⇒ Object
38
|
# File 'lib/flor/unit/models.rb', line 38
def storage; unit.storage; end
|
#to_h ⇒ Object
Also known as:
to_dump_h
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/flor/unit/models.rb', line 84
def to_h
values.inject({}) do |h, (k, v)|
if k == :content
h[:data] = data
else
h[k] = v
end
h
end
end
|
#unit ⇒ Object
37
|
# File 'lib/flor/unit/models.rb', line 37
def unit; self.class.unit; end
|