Class: WEEL::ReadStructure
- Inherits:
-
Object
- Object
- WEEL::ReadStructure
show all
- Defined in:
- lib/weel.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data, endpoints, local, additional) ⇒ ReadStructure
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/weel.rb', line 47
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
Marshal.load(Marshal.dump(v))
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/weel.rb', line 72
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
|
Instance Attribute Details
#additional ⇒ Object
Returns the value of attribute additional.
103
104
105
|
# File 'lib/weel.rb', line 103
def additional
@additional
end
|
Instance Method Details
#data ⇒ Object
94
95
96
|
# File 'lib/weel.rb', line 94
def data
ReadHash.new(@__weel_data)
end
|
#endpoints ⇒ Object
97
98
99
|
# File 'lib/weel.rb', line 97
def endpoints
ReadHash.new(@__weel_endpoints)
end
|
#local ⇒ Object
100
101
102
|
# File 'lib/weel.rb', line 100
def local
@__weel_local&.first
end
|
#to_json(*a) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/weel.rb', line 64
def to_json(*a)
{
'data' => @__weel_data,
'endpoints' => @__weel_endpoints,
'additional' => @additional,
}.to_json(*a)
end
|
#update(d, e, s) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/weel.rb', line 86
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
|