Class: Backburner::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/backburner/connection.rb

Constant Summary collapse

STATUS_REGEXP =
/(\d+) ([0-9A-z ]+)$/
PROMPT_REGEXP =
/\nbackburner(\(controller\))?>/i
XML_COMMENT_REGEXP =
/<!--.+-->/

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_bodyObject (readonly)

Returns the value of attribute last_body.



12
13
14
# File 'lib/backburner/connection.rb', line 12

def last_body
  @last_body
end

#last_messageObject (readonly)

Returns the value of attribute last_message.



12
13
14
# File 'lib/backburner/connection.rb', line 12

def last_message
  @last_message
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



12
13
14
# File 'lib/backburner/connection.rb', line 12

def last_response
  @last_response
end

#last_sizeObject (readonly)

Returns the value of attribute last_size.



12
13
14
# File 'lib/backburner/connection.rb', line 12

def last_size
  @last_size
end

#last_statusObject (readonly)

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

#closeObject



23
24
25
# File 'lib/backburner/connection.rb', line 23

def close
  @session.close
end

#disable_promptObject



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

#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

Returns:

  • (Boolean)


61
62
63
# File 'lib/backburner/connection.rb', line 61

def proceed?
  @last_status < 200 || @last_status > 299
end

#ready?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/backburner/connection.rb', line 65

def ready?
  @last_status == 250
end

#send_data(data) ⇒ Object



52
53
54
# File 'lib/backburner/connection.rb', line 52

def send_data data
  @session.cmd 'String' => data
end

#send_text(data) ⇒ Object



56
57
58
59
# File 'lib/backburner/connection.rb', line 56

def send_text data
  @last_response = @session.cmd data
  parse_response
end