Class: ServiceRunner::Service
- Inherits:
-
Object
- Object
- ServiceRunner::Service
- Defined in:
- lib/service_runner/service.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#start_command ⇒ Object
Returns the value of attribute start_command.
-
#stop_command ⇒ Object
Returns the value of attribute stop_command.
Class Method Summary collapse
Instance Method Summary collapse
- #default_options ⇒ Object
-
#initialize(name) ⇒ Service
constructor
A new instance of Service.
- #interpolate(command, options) ⇒ Object
- #root ⇒ Object
- #start(options = {}) ⇒ Object
- #stop(options = {}) ⇒ Object
Constructor Details
#initialize(name) ⇒ Service
Returns a new instance of Service.
14 15 16 |
# File 'lib/service_runner/service.rb', line 14 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/service_runner/service.rb', line 3 def name @name end |
#start_command ⇒ Object
Returns the value of attribute start_command.
3 4 5 |
# File 'lib/service_runner/service.rb', line 3 def start_command @start_command end |
#stop_command ⇒ Object
Returns the value of attribute stop_command.
3 4 5 |
# File 'lib/service_runner/service.rb', line 3 def stop_command @stop_command end |
Class Method Details
.define(name) {|service| ... } ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/service_runner/service.rb', line 39 def define(name) service = new(name) yield service @services ||= {} @services[name] = service end |
.get(name) ⇒ Object
47 48 49 |
# File 'lib/service_runner/service.rb', line 47 def get(name) @services[name] end |
Instance Method Details
#default_options ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/service_runner/service.rb', line 5 def { 'bundle' => 'bundle exec', 'env' => 'production', 'log' => "#{root}/log/#{name}.log", 'pid' => "#{root}/tmp/pids/#{name}.pid" } end |
#interpolate(command, options) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/service_runner/service.rb', line 18 def interpolate(command, ) interpolations = .merge() interpolations.inject(command) do |command_string, (key, value)| command_string.gsub(/:\{?#{key}\}?/) { value } end end |
#root ⇒ Object
34 35 36 |
# File 'lib/service_runner/service.rb', line 34 def root Dir.getwd end |
#start(options = {}) ⇒ Object
26 27 28 |
# File 'lib/service_runner/service.rb', line 26 def start( = {}) interpolate(start_command, ) end |
#stop(options = {}) ⇒ Object
30 31 32 |
# File 'lib/service_runner/service.rb', line 30 def stop( = {}) interpolate(stop_command, ) end |