Class: Offshore::Host
- Inherits:
-
Object
- Object
- Offshore::Host
- Defined in:
- lib/offshore/client/host.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#base_uri ⇒ Object
end.
- #connection ⇒ Object
- #factory_create(name, attributes = {}) ⇒ Object
-
#factory_object(hash) ⇒ Object
TODO: move this to a config block.
-
#initialize(options) ⇒ Host
constructor
A new instance of Host.
- #path ⇒ Object
- #post(append_path, attributes = {}) ⇒ Object
- #snapshot_name ⇒ Object
- #suite_start ⇒ Object
- #suite_stop ⇒ Object
- #test_start(name) ⇒ Object
- #test_stop(name) ⇒ Object
Constructor Details
#initialize(options) ⇒ Host
Returns a new instance of Host.
62 63 64 65 66 67 |
# File 'lib/offshore/client/host.rb', line 62 def initialize() @host = [:host] @port = [:port] @path = [:path] @snapshot = [:snapshot] end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
61 62 63 |
# File 'lib/offshore/client/host.rb', line 61 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
61 62 63 |
# File 'lib/offshore/client/host.rb', line 61 def port @port end |
Instance Method Details
#base_uri ⇒ Object
end
21 22 23 24 25 26 |
# File 'lib/offshore/client/host.rb', line 21 def base_uri with_http = host with_http = "http://#{host}" unless (host =~ /^https?:/) == 0 need_port = port || 80 "#{with_http}:#{need_port}" end |
#connection ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/offshore/client/host.rb', line 28 def connection return @connection if @connection connection_class = Faraday.respond_to?(:new) ? ::Faraday : ::Faraday::Connection timeout_seconds = 5*60 # 5 minutes @connection = connection_class.new(base_uri, :timeout => timeout_seconds) do |builder| builder.use Faraday::Request::UrlEncoded if defined?(Faraday::Request::UrlEncoded) builder.adapter Faraday.default_adapter end @connection end |
#factory_create(name, attributes = {}) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/offshore/client/host.rb', line 97 def factory_create(name, attributes={}) data = { :name => name } data[:attributes] = attributes hash = post(:factory_create, data) factory_object(hash) end |
#factory_object(hash) ⇒ Object
TODO: move this to a config block
105 106 107 |
# File 'lib/offshore/client/host.rb', line 105 def factory_object(hash) hash["class_name"].constantize.find(hash["id"]) end |
#path ⇒ Object
75 76 77 |
# File 'lib/offshore/client/host.rb', line 75 def path @path ||= "/offshore_tests" end |
#post(append_path, attributes = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/offshore/client/host.rb', line 40 def post(append_path, attributes={}) attributes[:hostname] = `hostname` # always send hostname while true do http_response = connection.post("#{self.path}/#{append_path}", attributes) if http_response.success? return MultiJson.decode(http_response.body) elsif http_response.status.to_s == Offshore::WAIT_CODE.to_s sleep 2 # two seconds and try again else begin hash = MultiJson.decode(http_response.body) = "Error in offshore connection (#{append_path}): #{hash}" rescue = "Error in offshore connection (#{append_path}): #{http_response.status}" end raise end end end |
#snapshot_name ⇒ Object
69 70 71 72 73 |
# File 'lib/offshore/client/host.rb', line 69 def snapshot_name return nil if @snapshot == true return "none" if @snapshot == false @snapshot end |
#suite_start ⇒ Object
79 80 81 82 83 |
# File 'lib/offshore/client/host.rb', line 79 def suite_start attributes = {} attributes[:snapshot] = snapshot_name hash = post(:suite_start, attributes) end |
#suite_stop ⇒ Object
85 86 87 |
# File 'lib/offshore/client/host.rb', line 85 def suite_stop hash = post(:suite_stop) end |
#test_start(name) ⇒ Object
89 90 91 |
# File 'lib/offshore/client/host.rb', line 89 def test_start(name) hash = post(:test_start, { :name => name }) end |
#test_stop(name) ⇒ Object
93 94 95 |
# File 'lib/offshore/client/host.rb', line 93 def test_stop(name) hash = post(:test_stop, { :name => name }) end |