class WEEL::ManipulateStructure

Attributes

additional[R]

Public Class Methods

new(data,endpoints,status,local,additional) click to toggle source
# 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

Public Instance Methods

changed_data() click to toggle source
# 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() click to toggle source
# File lib/weel.rb, line 169
def changed_endpoints
  @changed_endpoints.uniq
end
changed_status() click to toggle source
# File lib/weel.rb, line 181
def changed_status
  @changed_status != "#{status.id}-#{status.message}"
end
data() click to toggle source
# File lib/weel.rb, line 185
def data
  ManipulateHash.new(@__weel_data,@touched_data,@changed_data)
end
endpoints() click to toggle source
# File lib/weel.rb, line 188
def endpoints
  ManipulateHash.new(@__weel_endpoints,@touched_endpoints,@changed_endpoints)
end
local() click to toggle source
# File lib/weel.rb, line 191
def local
  @__weel_local&.first
end
method_missing(m,*args,&block) click to toggle source
# 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
original_data() click to toggle source
# File lib/weel.rb, line 173
def original_data
  @__weel_data_orig.transform_values{|val| Marshal.load(val) rescue nil }
end
original_endpoints() click to toggle source
# File lib/weel.rb, line 177
def original_endpoints
  @__weel_endpoints_orig.transform_values{|val| Marshal.load(val) rescue nil }
end
status() click to toggle source
# File lib/weel.rb, line 194
def status
  @__weel_status
end
to_json(*a) click to toggle source
# 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) click to toggle source
# 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