Class: WEEL::ManipulateStructure
- Inherits:
-
Object
- Object
- WEEL::ManipulateStructure
show all
- Defined in:
- lib/weel.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(data, endpoints, status, local, additional) ⇒ ManipulateStructure
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/weel.rb', line 100
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/weel.rb', line 127
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 Method Details
#changed_data ⇒ Object
142
143
144
145
146
147
148
149
150
|
# File 'lib/weel.rb', line 142
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
end
|
#changed_endpoints ⇒ Object
151
152
153
|
# File 'lib/weel.rb', line 151
def changed_endpoints
@changed_endpoints
end
|
#changed_status ⇒ Object
163
164
165
|
# File 'lib/weel.rb', line 163
def changed_status
@changed_status != "#{status.id}-#{status.message}"
end
|
#data ⇒ Object
167
168
169
|
# File 'lib/weel.rb', line 167
def data
ManipulateHash.new(@__weel_data,@touched_data,@changed_data)
end
|
#endpoints ⇒ Object
170
171
172
|
# File 'lib/weel.rb', line 170
def endpoints
ManipulateHash.new(@__weel_endpoints,@touched_endpoints,@changed_endpoints)
end
|
#local ⇒ Object
173
174
175
|
# File 'lib/weel.rb', line 173
def local
@__weel_local.first
end
|
#original_data ⇒ Object
155
156
157
|
# File 'lib/weel.rb', line 155
def original_data
@__weel_data_orig.transform_values{|val| Marshal.load(val) rescue nil }
end
|
#original_endpoints ⇒ Object
159
160
161
|
# File 'lib/weel.rb', line 159
def original_endpoints
@__weel_endpoints_orig.transform_values{|val| Marshal.load(val) rescue nil }
end
|
#status ⇒ Object
176
177
178
|
# File 'lib/weel.rb', line 176
def status
@__weel_status
end
|
#to_json(*a) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/weel.rb', line 115
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
|