Module: MultiProcess::Process::Rails
- Defined in:
- lib/multi_process/process/rails.rb
Overview
Provides functionality for a process that is a rails server process.
Include this module if required.
Functions include port generation, default server command and availability check based on if server socket is reachable.
Instance Attribute Summary collapse
-
#server ⇒ Object
Server wrapper given as argument to ‘server` action.
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#configure(opts) ⇒ Object
Load environment options from initialize options.
- #initialize(opts = {}) ⇒ Object
- #port ⇒ Object
- #port=(port) ⇒ Object
- #server_command ⇒ Object
- #start_childprocess(*args) ⇒ Object
Instance Attribute Details
#server ⇒ Object
Server wrapper given as argument to ‘server` action.
15 16 17 |
# File 'lib/multi_process/process/rails.rb', line 15 def server @server end |
Instance Method Details
#available? ⇒ Boolean
41 42 43 44 45 46 47 48 |
# File 'lib/multi_process/process/rails.rb', line 41 def available? raise ArgumentError.new "Cannot check availability for port #{port}." if port.zero? TCPSocket.new('localhost', port).close true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH false end |
#configure(opts) ⇒ Object
Load environment options from initialize options.
52 53 54 55 56 57 |
# File 'lib/multi_process/process/rails.rb', line 52 def configure(opts) super puts 'Configure RAILS' self.dir = Dir.pwd self.dir = opts[:dir].to_s if opts[:dir] end |
#initialize(opts = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/multi_process/process/rails.rb', line 17 def initialize(opts = {}) self.server = opts[:server] if opts[:server] self.port = opts[:port] if opts[:port] super(*server_command, opts) end |
#port ⇒ Object
37 38 39 |
# File 'lib/multi_process/process/rails.rb', line 37 def port @port ||= free_port end |
#port=(port) ⇒ Object
32 33 34 35 |
# File 'lib/multi_process/process/rails.rb', line 32 def port=(port) port = Integer(port) @port = port.zero? ? free_port : port end |
#server_command ⇒ Object
24 25 26 |
# File 'lib/multi_process/process/rails.rb', line 24 def server_command ['rails', 'server', server, '--port', port].compact.map(&:to_s) end |
#start_childprocess(*args) ⇒ Object
59 60 61 |
# File 'lib/multi_process/process/rails.rb', line 59 def start_childprocess(*args) Dir.chdir(dir) { super } end |