Class: Procmon::ProcessFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/procmon/dsl/process_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes, process_block) ⇒ ProcessFactory

Returns a new instance of ProcessFactory.



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

def initialize(name, attributes, process_block)
  @checks = {}
  @name = name
  @attributes = attributes
  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



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/procmon/dsl/process_factory.rb', line 15

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.



3
4
5
# File 'lib/procmon/dsl/process_factory.rb', line 3

def attributes
  @attributes
end

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

Returns the value of attribute checks.



3
4
5
# File 'lib/procmon/dsl/process_factory.rb', line 3

def checks
  @checks
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/procmon/dsl/process_factory.rb', line 3

def name
  @name
end

Instance Method Details

#create_processObject



37
38
39
# File 'lib/procmon/dsl/process_factory.rb', line 37

def create_process
  Process.new(@name, @checks, @attributes)
end