Class: Backburner::Connection
- Inherits:
-
Object
- Object
- Backburner::Connection
show all
- Defined in:
- lib/backburner/connection.rb
Constant Summary
collapse
- STATUS_REGEXP =
/(\d+) ([0-9A-z ]+)$/
- PROMPT_REGEXP =
/\n?backburner(\(controller\))?>/i
/<!--.+-->/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(host = '127.0.0.1', port = 3234) ⇒ Connection
Returns a new instance of Connection.
14
15
16
17
|
# File 'lib/backburner/connection.rb', line 14
def initialize host='127.0.0.1', port=3234
@session = Net::Telnet.new('Host' => host, 'Port' => port, 'Prompt' => PROMPT_REGEXP)
@session.waitfor 'Match' => PROMPT_REGEXP
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
19
20
21
|
# File 'lib/backburner/connection.rb', line 19
def method_missing method_name
RemoteCommand.new method_name, self
end
|
Instance Attribute Details
#last_body ⇒ Object
Returns the value of attribute last_body.
12
13
14
|
# File 'lib/backburner/connection.rb', line 12
def last_body
@last_body
end
|
#last_message ⇒ Object
Returns the value of attribute last_message.
12
13
14
|
# File 'lib/backburner/connection.rb', line 12
def last_message
@last_message
end
|
#last_response ⇒ Object
Returns the value of attribute last_response.
12
13
14
|
# File 'lib/backburner/connection.rb', line 12
def last_response
@last_response
end
|
#last_size ⇒ Object
Returns the value of attribute last_size.
12
13
14
|
# File 'lib/backburner/connection.rb', line 12
def last_size
@last_size
end
|
#last_status ⇒ Object
Returns the value of attribute last_status.
12
13
14
|
# File 'lib/backburner/connection.rb', line 12
def last_status
@last_status
end
|
Instance Method Details
#close ⇒ Object
23
24
25
|
# File 'lib/backburner/connection.rb', line 23
def close
@session.close
end
|
#cmd(data) ⇒ Object
55
56
57
58
|
# File 'lib/backburner/connection.rb', line 55
def cmd data
@last_response = @session.cmd data
parse_response
end
|
#disable_prompt ⇒ Object
27
28
29
30
31
|
# File 'lib/backburner/connection.rb', line 27
def disable_prompt
response = exec 'String' => 'set prompt off'
return response if @last_status==201
raise
end
|
#empty? ⇒ Boolean
92
93
94
|
# File 'lib/backburner/connection.rb', line 92
def empty?
@last_size == 0
end
|
#error? ⇒ Boolean
88
89
90
|
# File 'lib/backburner/connection.rb', line 88
def error?
(@last_status||0) > 399
end
|
#exec(arg_hash) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/backburner/connection.rb', line 33
def exec arg_hash
xml_string = ''
first = true
@session.cmd arg_hash do |response|
if first
response =~ /(\d+) (\d*)(.*)/
@last_status = $1.to_i
@last_size = $2.to_i
@last_message = $3
first = false
next
end
xml_string += response
end
xml_string = xml_string.sub(/backburner>$/, '')
DataObject.new xml_string
end
|
#proceed? ⇒ Boolean
80
81
82
|
# File 'lib/backburner/connection.rb', line 80
def proceed?
@last_status < 200 || @last_status > 299
end
|
#ready? ⇒ Boolean
76
77
78
|
# File 'lib/backburner/connection.rb', line 76
def ready?
(@last_status||0) == 251
end
|
#send_data ⇒ Object
52
53
|
# File 'lib/backburner/connection.rb', line 52
def send_data
end
|
#send_text(command_data, data = nil) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/backburner/connection.rb', line 60
def send_text command_data, data=nil
request = "#{command_data}"
request_hash = {}
if data
request_hash['Match'] = STATUS_REGEXP
request += " #{data.bytesize+14}"
end
request_hash['String'] = request
@last_response = @session.cmd request_hash
parse_status
@last_response = @session.puts data
@last_response = @session.waitfor('Match' => STATUS_REGEXP)
@session.waitfor 'Match' => PROMPT_REGEXP
parse_status
end
|