Class: WEEL::ManipulateStructure
- Inherits:
-
Object
- Object
- WEEL::ManipulateStructure
show all
- Defined in:
- lib/weel.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data, endpoints, status, local, additional) ⇒ ManipulateStructure
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/weel.rb', line 106
def initialize(data,endpoints,status,local,additional)
@__weel_data = data
@__weel_data_orig = @__weel_data.transform_values{|val| Marshal.dump(val) } rescue nil
@__weel_endpoints = endpoints
@__weel_endpoints_orig = @__weel_endpoints.transform_values{|val| Marshal.dump(val) }
@__weel_status = status
@__weel_local = local
@changed_status = "#{status.id}-#{status.message}"
@changed_data = []
@touched_data = []
@changed_endpoints = []
@touched_endpoints = []
@additional = additional
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/weel.rb', line 133
def method_missing(m,*args,&block)
if @additional.include?(m)
begin
tmp = Marshal.load(Marshal.dump(@additional[m]))
if tmp.is_a? Hash
ReadHash.new(tmp)
else
tmp
end
rescue
m.to_s rescue nil
end
end
end
|
Instance Attribute Details
#additional ⇒ Object
Returns the value of attribute additional.
197
198
199
|
# File 'lib/weel.rb', line 197
def additional
@additional
end
|
Instance Method Details
#changed_data ⇒ Object
160
161
162
163
164
165
166
167
168
|
# File 'lib/weel.rb', line 160
def changed_data
@touched_data.each do |e|
td = Marshal.dump(@__weel_data[e]) rescue nil
if td != @__weel_data_orig[e]
@changed_data << e
end
end
@changed_data.uniq
end
|
#changed_endpoints ⇒ Object
169
170
171
|
# File 'lib/weel.rb', line 169
def changed_endpoints
@changed_endpoints.uniq
end
|
#changed_status ⇒ Object
181
182
183
|
# File 'lib/weel.rb', line 181
def changed_status
@changed_status != "#{status.id}-#{status.message}"
end
|
#data ⇒ Object
185
186
187
|
# File 'lib/weel.rb', line 185
def data
ManipulateHash.new(@__weel_data,@touched_data,@changed_data)
end
|
#endpoints ⇒ Object
188
189
190
|
# File 'lib/weel.rb', line 188
def endpoints
ManipulateHash.new(@__weel_endpoints,@touched_endpoints,@changed_endpoints)
end
|
#local ⇒ Object
191
192
193
|
# File 'lib/weel.rb', line 191
def local
@__weel_local&.first
end
|
#original_data ⇒ Object
173
174
175
|
# File 'lib/weel.rb', line 173
def original_data
@__weel_data_orig.transform_values{|val| Marshal.load(val) rescue nil }
end
|
#original_endpoints ⇒ Object
177
178
179
|
# File 'lib/weel.rb', line 177
def original_endpoints
@__weel_endpoints_orig.transform_values{|val| Marshal.load(val) rescue nil }
end
|
#status ⇒ Object
194
195
196
|
# File 'lib/weel.rb', line 194
def status
@__weel_status
end
|
#to_json(*a) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/weel.rb', line 121
def to_json(*a)
{
'data' => @__weel_data,
'endpoints' => @__weel_endpoints,
'additional' => @additional,
'status' => {
'id' => @__weel_status.id,
'message' => @__weel_status.message
}
}.to_json(*a)
end
|
#update(d, e, s) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/weel.rb', line 148
def update(d,e,s)
d.each do |k,v|
data.send(k+'=',v)
end if d
e.each do |k,v|
endpoints.send(k+'=',v)
end if e
if s
status.update(s['id'],s['message'])
end
end
|