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

{{{



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/weel.rb', line 108

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



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/weel.rb', line 135

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.



199
200
201
# File 'lib/weel.rb', line 199

def additional
  @additional
end

Instance Method Details

#changed_dataObject



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

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



171
172
173
# File 'lib/weel.rb', line 171

def changed_endpoints
  @changed_endpoints.uniq
end

#changed_statusObject



183
184
185
# File 'lib/weel.rb', line 183

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

#dataObject



187
188
189
# File 'lib/weel.rb', line 187

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

#endpointsObject



190
191
192
# File 'lib/weel.rb', line 190

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

#localObject



193
194
195
# File 'lib/weel.rb', line 193

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

#original_dataObject



175
176
177
# File 'lib/weel.rb', line 175

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

#original_endpointsObject



179
180
181
# File 'lib/weel.rb', line 179

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

#statusObject



196
197
198
# File 'lib/weel.rb', line 196

def status
  @__weel_status
end

#to_json(*a) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/weel.rb', line 123

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



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/weel.rb', line 150

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