Class: WEEL::ReadStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/weel.rb

Overview

}}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, endpoints, local, additional) ⇒ ReadStructure

{{{



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/weel.rb', line 49

def initialize(data,endpoints,local,additional)
  @__weel_data = data.transform_values do |v|
    if Object.const_defined?(:XML) && XML.const_defined?(:Smart) && v.is_a?(XML::Smart::Dom)
      v.root.to_doc
    else
      begin
        v.deep_dup
      rescue
        v.to_s rescue nil
      end
    end
  end
  @__weel_endpoints = endpoints.transform_values{ |v| v.dup }
  @__weel_local = local
  @additional = additional
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/weel.rb', line 74

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.



105
106
107
# File 'lib/weel.rb', line 105

def additional
  @additional
end

Instance Method Details

#dataObject



96
97
98
# File 'lib/weel.rb', line 96

def data
  ReadHash.new(@__weel_data)
end

#endpointsObject



99
100
101
# File 'lib/weel.rb', line 99

def endpoints
  ReadHash.new(@__weel_endpoints)
end

#localObject



102
103
104
# File 'lib/weel.rb', line 102

def local
  ReadHash.new(@__weel_local)
end

#to_json(*a) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/weel.rb', line 66

def to_json(*a)
  {
    'data' => @__weel_data,
    'endpoints' => @__weel_endpoints,
    'additional' => @additional,
  }.to_json(*a)
end

#update(d, e, s) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/weel.rb', line 88

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
end