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

Instance Method Summary collapse

Instance Attribute Details

#portObject

Port server should be running on.

Default will be a free port determined when process is created.



21
22
23
# File 'lib/multi_process/process/rails.rb', line 21

def port
  @port
end

#serverObject

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

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
# File 'lib/multi_process/process/rails.rb', line 42

def available?
  raise ArgumentError.new "Cannot check availability for port #{port}." if port == 0

  TCPSocket.new('127.0.0.1', port).close
  true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
  false
end

#configure(opts) ⇒ Object

Load environment options from initialize options.



53
54
55
56
57
58
# File 'lib/multi_process/process/rails.rb', line 53

def configure(opts)
  super
  puts 'Configure RAILS'
  self.dir = Dir.pwd
  self.dir = opts[:dir].to_s if opts[:dir]
end

#initialize(opts = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/multi_process/process/rails.rb', line 23

def initialize(opts = {})
  self.server = opts[:server] if opts[:server]
  self.port   = opts[:port]   if opts[:port]

  super ['rails', 'server', server, '--port', port].reject(&:nil?).map(&:to_s), opts
end

#start_childprocess(*args) ⇒ Object



60
61
62
# File 'lib/multi_process/process/rails.rb', line 60

def start_childprocess(*args)
  Dir.chdir(dir) { super }
end