Class: ServiceRunner::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/service_runner/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/service_runner/service.rb', line 3

def name
  @name
end

#start_commandObject

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_commandObject

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

Yields:

  • (service)


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_optionsObject



5
6
7
8
9
10
11
12
# File 'lib/service_runner/service.rb', line 5

def default_options
  {
    '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, options)
  interpolations = default_options.merge(options)

  interpolations.inject(command) do |command_string, (key, value)|
    command_string.gsub(/:\{?#{key}\}?/) { value }
  end
end

#rootObject



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(options = {})
  interpolate(start_command, options)
end

#stop(options = {}) ⇒ Object



30
31
32
# File 'lib/service_runner/service.rb', line 30

def stop(options = {})
  interpolate(stop_command, options)
end