Class: Redom::Proxy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, info, extra = {}) ⇒ Proxy

Returns a new instance of Proxy.



3
4
5
6
7
8
9
10
# File 'lib/redom/proxy.rb', line 3

def initialize(conn, info, extra = {})
  @conn = conn
  @info = info
  @info[P_INFO_OID] = __id__ unless @info[P_INFO_OID]

  @solved = false
  @origin = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blck) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/redom/proxy.rb', line 13

def method_missing(name, *args, &blck)
  return @origin.send(name, *args, &block) if @solved && !@origin.is_a?(Proxy)

  if blck
    @conn.sync
    return @origin.send(name, *args, &block)
  end

  proxy = Proxy.new(@conn, [nil, _info[P_INFO_OID], name, _arg(args)], {:backtrace => caller[0]})
  @conn._bulk proxy
  proxy
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



11
12
13
# File 'lib/redom/proxy.rb', line 11

def origin
  @origin
end

Instance Method Details

#_infoObject



33
34
35
# File 'lib/redom/proxy.rb', line 33

def _info
  @info
end

#_origin(org) ⇒ Object



37
38
39
40
# File 'lib/redom/proxy.rb', line 37

def _origin(org)
  @solved = true
  @origin = org
end

#syncObject



26
27
28
29
30
31
# File 'lib/redom/proxy.rb', line 26

def sync
  unless @solved
    @conn.sync{}
  end
  @origin
end