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.



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

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

  if process_block.arity == 0
    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



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

def method_missing(name, *args)
  if args.size == 1 && name.to_s =~ /^(.*)=$/
    @attributes[$1.to_sym] = args.first
  elsif args.size == 1
    @attributes[name.to_sym] = args.first
  elsif args.size == 0 && name.to_s =~ /^(.*)!$/
    @attributes[$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.



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

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#watchesObject (readonly)

Returns the value of attribute watches.



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

def watches
  @watches
end

Instance Method Details

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



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

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

#monitor_children(&child_process_block) ⇒ Object



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

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

#to_processObject



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

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