Module: Redom::Connection

Includes:
Utils
Defined in:
lib/redom/connection.rb

Instance Method Summary collapse

Methods included from Utils

#_dispatcher, #_logger, dispatcher=, logger=

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
# File 'lib/redom/connection.rb', line 18

def method_missing(name, *args, &blck)
  window.method_missing(name, *args, &blck)
end

Instance Method Details

#_bulk(proxy) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/redom/connection.rb', line 34

def _bulk(proxy)
  fid = _fid
  stack = @proxies[fid] || @proxies[fid] = Hash.new
  stack[proxy._info[P_INFO_OID]] = proxy
  if stack.size == @buff_size
    sync
  end
end

#_cidObject



83
84
85
# File 'lib/redom/connection.rb', line 83

def _cid
  @ws.__id__
end

#_fidObject



87
88
89
# File 'lib/redom/connection.rb', line 87

def _fid
  "F#{Fiber.current.__id__}"
end

#_init(ws, opts) ⇒ Object

Initialization



27
28
29
30
31
32
# File 'lib/redom/connection.rb', line 27

def _init(ws, opts)
  @ws = ws
  @proxies = Hash.new
  @buff_size = opts[:buff_size]
  self
end

#_send(msg) ⇒ Object



91
92
93
94
# File 'lib/redom/connection.rb', line 91

def _send(msg)
  _logger.debug "Message sent. ID='#{@ws.__id__}'\n#{msg}"
  @ws.send msg
end

#connections(filter = self.class) ⇒ Object



22
23
24
# File 'lib/redom/connection.rb', line 22

def connections(filter = self.class)
  _dispatcher.connections(filter)
end

#documentObject



14
15
16
# File 'lib/redom/connection.rb', line 14

def document
  Proxy.new(self, [:document], {:backtrace => caller[0]})
end

#on_closeObject



7
# File 'lib/redom/connection.rb', line 7

def on_close; end

#on_error(err) ⇒ Object



8
# File 'lib/redom/connection.rb', line 8

def on_error(err); end

#on_openObject

Default event handlers



6
# File 'lib/redom/connection.rb', line 6

def on_open; end

#sync(obj = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/redom/connection.rb', line 43

def sync(obj = nil)
  obj = _fid if obj == self
  if Connection === obj
    _dispatcher.run_task(obj, :sync, [_fid], nil)
    return
  end

  fid = obj ? obj : _fid
  stack = @proxies[fid]
  return if !stack || stack.empty?

  msg = []
  stack.each { |k, v|
    msg << v._info
  }

  rsp = Fiber.yield(msg)

  error = nil
  while result = rsp.shift
    proxy = stack[result[0]]
    if Array === result[1]
      case result[1][0]
      when TYPE_UNDEFINED
        # TODO
      when TYPE_PROXY
        proxy._origin proxy
      when TYPE_ERROR
        # TODO
      end
    else
      proxy._origin result[1]
    end
  end

  stack.clear

  on_error(error) if error
end

#windowObject

Proxy of browser objects



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

def window
  Proxy.new(self, [:window], {:backtrace => caller[0]})
end