Class: Cucumba::Rails
- Inherits:
-
Object
- Object
- Cucumba::Rails
- Defined in:
- lib/cucumba/rails.rb,
lib/cucumba/rails/model.rb,
lib/cucumba/rails/runner.rb
Overview
Cucumba rails client
Defined Under Namespace
Classes: Model, ServerNotFound
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#drb_port ⇒ Object
readonly
Returns the value of attribute drb_port.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #drb_url ⇒ Object
- #execute(code) ⇒ Object (also: #e)
-
#initialize(config) ⇒ Rails
constructor
A new instance of Rails.
- #model(model_name) ⇒ Object (also: #m)
- #rails_root ⇒ Object
- #rails_start! ⇒ Object
- #rails_stop! ⇒ Object
- #run? ⇒ Boolean
-
#url ⇒ Object
url where rails application lives.
Constructor Details
#initialize(config) ⇒ Rails
Returns a new instance of Rails.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cucumba/rails.rb', line 13 def initialize(config) @host = config[:host] @port = config[:port] || 80 @drb_port = @port+1000 @run = config[:run] @description = config[:desc] @environment = config[:env] if config[:path] @path = File.join(config[:path]) else @path = File.join('.') end @path = File.(@path) @pid_file = File.join(@path,'tmp/pids/server.pid') @server = DRbObject.new(nil, drb_url) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
11 12 13 |
# File 'lib/cucumba/rails.rb', line 11 def description @description end |
#drb_port ⇒ Object (readonly)
Returns the value of attribute drb_port.
11 12 13 |
# File 'lib/cucumba/rails.rb', line 11 def drb_port @drb_port end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
11 12 13 |
# File 'lib/cucumba/rails.rb', line 11 def environment @environment end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/cucumba/rails.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/cucumba/rails.rb', line 11 def port @port end |
Instance Method Details
#drb_url ⇒ Object
35 36 37 |
# File 'lib/cucumba/rails.rb', line 35 def drb_url 'druby://'+@host+':'+@drb_port.to_s end |
#execute(code) ⇒ Object Also known as: e
52 53 54 |
# File 'lib/cucumba/rails.rb', line 52 def execute(code) @server.execute(code) end |
#model(model_name) ⇒ Object Also known as: m
47 48 49 |
# File 'lib/cucumba/rails.rb', line 47 def model(model_name) Model.new(model_name,@server) end |
#rails_root ⇒ Object
39 40 41 |
# File 'lib/cucumba/rails.rb', line 39 def rails_root @path end |
#rails_start! ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/cucumba/rails/runner.rb', line 8 def rails_start! if run? puts "=> #{self.description} booting..." boot! wait_untill_alive! end end |
#rails_stop! ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/cucumba/rails/runner.rb', line 16 def rails_stop! pid = File.read(@pid_file).to_i puts "=> Killing alive server #{self.description}(pid:#{pid})" Process.kill('INT',pid) rescue Errno::ESRCH, Errno::ENOENT puts "=> Server #{self.description} is not running" end |
#run? ⇒ Boolean
43 44 45 |
# File 'lib/cucumba/rails.rb', line 43 def run? @run end |
#url ⇒ Object
url where rails application lives
31 32 33 |
# File 'lib/cucumba/rails.rb', line 31 def url 'http://'+@host+':'+@port.to_s end |