Class: Bluepill::ProcessProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/bluepill/dsl/process_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process_name, attributes, process_block) ⇒ ProcessProxy

Returns a new instance of ProcessProxy.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bluepill/dsl/process_proxy.rb', line 4

def initialize(process_name, attributes, process_block)
  @name = process_name
  @attributes = attributes
  @watches = {}

  if process_block.arity.zero?
    instance_eval(&process_block)
  else
    instance_exec(self, &process_block)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bluepill/dsl/process_proxy.rb', line 16

def method_missing(name, *args)
  if args.size == 1 && name.to_s =~ /^(.*)=$/
    @attributes[Regexp.last_match[1].to_sym] = args.first
  elsif args.size == 1
    @attributes[name.to_sym] = args.first
  elsif args.empty? && name.to_s =~ /^(.*)!$/
    @attributes[Regexp.last_match[1].to_sym] = true
  elsif args.empty? && @attributes.key?(name.to_sym)
    @attributes[name.to_sym]
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/bluepill/dsl/process_proxy.rb', line 3

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/bluepill/dsl/process_proxy.rb', line 3

def name
  @name
end

#watchesObject (readonly)

Returns the value of attribute watches.



3
4
5
# File 'lib/bluepill/dsl/process_proxy.rb', line 3

def watches
  @watches
end

Instance Method Details

#checks(name, options = {}) ⇒ Object



30
31
32
# File 'lib/bluepill/dsl/process_proxy.rb', line 30

def checks(name, options = {})
  @watches[name] = options
end

#monitor_children(&child_process_block) ⇒ Object



34
35
36
37
# File 'lib/bluepill/dsl/process_proxy.rb', line 34

def monitor_children(&child_process_block)
  @attributes[:monitor_children] = true
  @attributes[:child_process_block] = child_process_block
end

#to_processObject



39
40
41
# File 'lib/bluepill/dsl/process_proxy.rb', line 39

def to_process
  Process.new(@name, @watches, @attributes)
end