Class: WEEL::ReadStructure

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

Overview

}}}

Instance Method Summary collapse

Constructor Details

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

{{{



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/weel.rb', line 46

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



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

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 Method Details

#dataObject



89
90
91
# File 'lib/weel.rb', line 89

def data
  ReadHash.new(@__weel_data)
end

#endpointsObject



92
93
94
# File 'lib/weel.rb', line 92

def endpoints
  ReadHash.new(@__weel_endpoints)
end

#localObject



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

def local
  @__weel_local.first
end

#to_json(*a) ⇒ Object



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

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