class Openplacos::ProxyObjectInterface

Public Class Methods

new(connection_, proxyobj_, name_, methods_) click to toggle source

Interface abstraction contruct from introspect

# File lib/openplacos/libclient.rb, line 392
def initialize(connection_, proxyobj_, name_, methods_)
  @connection = connection_
  @proxyobject = proxyobj_
  @name    = name_
  @methods = Hash.new
  methods_.each {  |meth|
    @methods[meth] = define_method(meth)
  }
end

Public Instance Methods

define_method(name_) click to toggle source

Define a proxyfied method from its name

# File lib/openplacos/libclient.rb, line 403
    def define_method(name_)
     if name_=="read"
     methdef =  <<-eos
                   def read(option_ = {})
                     res = JSON.parse(@connection.token.get('/ressources/#{@proxyobject.path}', :params => {'iface'=> '#{@name}', 'options' => (option_).to_json}).body)
                     res["value"]
                   end
eos
    end
    if name_=="write"
     methdef =  <<-eos
                   def write(value_,option_ = {})
                     res = JSON.parse(@connection.token.post('/ressources/#{@proxyobject.path}', :params => {'iface'=> '#{@name}', 'value' => [value_].to_json, 'options' => (option_).to_json}).body)
                     res["status"]
                   end
eos
    end
    
        instance_eval( methdef )
      end