Class: Kanal::Core::Conditions::ConditionPackCreator

Inherits:
Object
  • Object
show all
Includes:
Logging::Logger
Defined in:
lib/kanal/core/conditions/condition_pack_creator.rb

Overview

This class helps in condition pack creation with the help of dsl

Constant Summary collapse

TEMP_NAME =
:temp_name

Instance Method Summary collapse

Methods included from Logging::Logger

#logger

Constructor Details

#initialize(name) ⇒ ConditionPackCreator

Returns a new instance of ConditionPackCreator.



17
18
19
20
# File 'lib/kanal/core/conditions/condition_pack_creator.rb', line 17

def initialize(name)
  @name = name
  @conditions = []
end

Instance Method Details

#add_condition(name, &block) ⇒ Object



48
49
50
51
52
# File 'lib/kanal/core/conditions/condition_pack_creator.rb', line 48

def add_condition(name, &block)
  creator = ConditionCreator.new name
  condition = creator.create(&block)
  @conditions.append condition
end

#create(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/kanal/core/conditions/condition_pack_creator.rb', line 22

def create(&block)
  instance_eval(&block)

  unless @name
    logger.fatal "Attempted to create condition pack without name"

    raise "Please provide condition pack name"
  end

  if @conditions.empty?
    logger.fatal "Attempted to create condition pack #{@name} without conditions provided"

    raise "Please provide conditions for condition pack #{@name}"
  end

  logger.debug "Creating condition pack '#{@name}'"

  pack = ConditionPack.new(@name)

  @conditions.each do |c|
    pack.register_condition c
  end

  pack
end