Class: WEEL::ManipulateStructure

Inherits:
Object
  • Object
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

{{{



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/weel.rb', line 145

def initialize(data,endpoints,status,local,additional)
  @__weel_data = data
  @__weel_data_orig = @__weel_data.transform_values{|val|  MessagePack.pack(val) rescue nil }
  @__weel_endpoints = endpoints
  @__weel_endpoints_orig = @__weel_endpoints.transform_values{|val|  MessagePack.pack(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



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/weel.rb', line 172

def method_missing(m,*args,&block)
  if @additional.include?(m)
    begin
      tmp = @additional[m].deep_dup
      if tmp.is_a? Hash
        ReadHash.new(tmp)
      else
        tmp
      end
    rescue
      m.to_s rescue nil
    end
  end
end

Instance Attribute Details

#additionalObject (readonly)

Returns the value of attribute additional.



236
237
238
# File 'lib/weel.rb', line 236

def additional
  @additional
end

Instance Method Details

#changed_dataObject



199
200
201
202
203
204
205
206
207
# File 'lib/weel.rb', line 199

def changed_data
  @touched_data.each do |e|
    td =  MessagePack.pack(@__weel_data[e]) rescue nil
    if td != @__weel_data_orig[e]
      @changed_data << e
    end
  end
  @changed_data.uniq
end

#changed_endpointsObject



208
209
210
# File 'lib/weel.rb', line 208

def changed_endpoints
  @changed_endpoints.uniq
end

#changed_statusObject



220
221
222
# File 'lib/weel.rb', line 220

def changed_status
  @changed_status != "#{status.id}-#{status.message}"
end

#dataObject



224
225
226
# File 'lib/weel.rb', line 224

def data
  ManipulateHash.new(@__weel_data,@touched_data,@changed_data)
end

#endpointsObject



227
228
229
# File 'lib/weel.rb', line 227

def endpoints
  ManipulateHash.new(@__weel_endpoints,@touched_endpoints,@changed_endpoints)
end

#localObject



230
231
232
# File 'lib/weel.rb', line 230

def local
  ManipulateHash.new(@__weel_local,[],[])
end

#original_dataObject



212
213
214
# File 'lib/weel.rb', line 212

def original_data
  @__weel_data_orig.transform_values{|val| MessagePack.unpack(val) rescue nil }
end

#original_endpointsObject



216
217
218
# File 'lib/weel.rb', line 216

def original_endpoints
  @__weel_endpoints_orig.transform_values{|val| MessagePack.unpack(val) rescue nil }
end

#statusObject



233
234
235
# File 'lib/weel.rb', line 233

def status
  @__weel_status
end

#to_json(*a) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/weel.rb', line 160

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



187
188
189
190
191
192
193
194
195
196
197
# File 'lib/weel.rb', line 187

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