Class: Openplacos::ProxyObjectInterface

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

Instance Method Summary collapse

Constructor Details

#initialize(connection_, proxyobj_, name_, methods_) ⇒ ProxyObjectInterface

Interface abstraction contruct from introspect



393
394
395
396
397
398
399
400
401
# File 'lib/openplacos/libclient.rb', line 393

def initialize(connection_, proxyobj_, name_, methods_)
  @connection = connection_
  @proxyobject = proxyobj_
  @name    = name_
  @methods = Hash.new
  methods_.each {  |meth|
    @methods[meth] = define_method(meth)
  }
end

Instance Method Details

#define_method(name_) ⇒ Object

Define a proxyfied method from its name



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/openplacos/libclient.rb', line 404

def define_method(name_)
     if name_=="read"
     methdef =  "             def read(option_ = {})\n               res = JSON.parse(@connection.token.get('/ressources/\#{@proxyobject.path}', :params => {'iface'=> '\#{@name}', 'options' => (option_).to_json}).body)\n               res[\"value\"]\n             end\n"
    end
    if name_=="write"
     methdef =  "             def write(value_,option_ = {})\n               res = JSON.parse(@connection.token.post('/ressources/\#{@proxyobject.path}', :params => {'iface'=> '\#{@name}', 'value' => [value_].to_json, 'options' => (option_).to_json}).body)\n               res[\"status\"]\n             end\n"
    end
    
  instance_eval( methdef )
end