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

{{{



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/weel.rb', line 86

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/weel.rb', line 111

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.



142
143
144
# File 'lib/weel.rb', line 142

def additional
  @additional
end

Instance Method Details

#dataObject



133
134
135
# File 'lib/weel.rb', line 133

def data
  ReadHash.new(@__weel_data)
end

#endpointsObject



136
137
138
# File 'lib/weel.rb', line 136

def endpoints
  ReadHash.new(@__weel_endpoints)
end

#localObject



139
140
141
# File 'lib/weel.rb', line 139

def local
  ReadHash.new(@__weel_local)
end

#to_json(*a) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/weel.rb', line 103

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

#update(d, e, s) ⇒ Object



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

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