Class: OopRailsServer::RailsServer
- Inherits:
-
Object
- Object
- OopRailsServer::RailsServer
- Defined in:
- lib/oop_rails_server/rails_server.rb
Defined Under Namespace
Classes: CommandFailedError
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rails_root ⇒ Object
readonly
Returns the value of attribute rails_root.
-
#rails_version ⇒ Object
readonly
Returns the value of attribute rails_version.
Instance Method Summary collapse
- #get(path, options = { }) ⇒ Object
- #get_response(path, options = { }) ⇒ Object
-
#initialize(options) ⇒ RailsServer
constructor
A new instance of RailsServer.
- #start! ⇒ Object
- #stop! ⇒ Object
- #uri_for(path) ⇒ Object
Constructor Details
#initialize(options) ⇒ RailsServer
Returns a new instance of RailsServer.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/oop_rails_server/rails_server.rb', line 10 def initialize() .assert_valid_keys( :name, :template_paths, :runtime_base_directory, :rails_version, :rails_env, :additional_gemfile_lines ) @name = [:name] || raise(ArgumentError, "You must specify a name for the Rails server") @template_paths = [:template_paths] || raise(ArgumentError, "You must specify one or more template paths") @template_paths = Array(@template_paths).map { |t| File.(t) } @runtime_base_directory = [:runtime_base_directory] || raise(ArgumentError, "You must specify a runtime_base_directory") @runtime_base_directory = File.(@runtime_base_directory) @rails_version = [:rails_version] || :default @rails_env = ([:rails_env] || 'production').to_s @additional_gemfile_lines = Array([:additional_gemfile_lines] || [ ]) @rails_root = File.join(@runtime_base_directory, rails_version.to_s, name.to_s) @port = 20_000 + rand(10_000) @server_pid = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/oop_rails_server/rails_server.rb', line 8 def name @name end |
#rails_root ⇒ Object (readonly)
Returns the value of attribute rails_root.
8 9 10 |
# File 'lib/oop_rails_server/rails_server.rb', line 8 def rails_root @rails_root end |
#rails_version ⇒ Object (readonly)
Returns the value of attribute rails_version.
8 9 10 |
# File 'lib/oop_rails_server/rails_server.rb', line 8 def rails_version @rails_version end |
Instance Method Details
#get(path, options = { }) ⇒ Object
43 44 45 |
# File 'lib/oop_rails_server/rails_server.rb', line 43 def get(path, = { }) get_response(path, ).body.strip end |
#get_response(path, options = { }) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/oop_rails_server/rails_server.rb', line 52 def get_response(path, = { }) uri = uri_for(path) data = Net::HTTP.get_response(uri) unless data.code.to_s == '200' || [:ignore_status_code] raise "'#{uri}' returned #{data.code.inspect}, not 200; body was: #{data.body.strip}" end data end |
#start! ⇒ Object
35 36 37 |
# File 'lib/oop_rails_server/rails_server.rb', line 35 def start! do_start! unless server_pid end |
#stop! ⇒ Object
39 40 41 |
# File 'lib/oop_rails_server/rails_server.rb', line 39 def stop! stop_server! if server_pid end |
#uri_for(path) ⇒ Object
47 48 49 50 |
# File 'lib/oop_rails_server/rails_server.rb', line 47 def uri_for(path) uri_string = "http://localhost:#{@port}/#{path}" URI.parse(uri_string) end |