Class: Kanal::Core::Conditions::ConditionCreator
- Inherits:
-
Object
- Object
- Kanal::Core::Conditions::ConditionCreator
- Includes:
- Logging::Logger
- Defined in:
- lib/kanal/core/conditions/condition_creator.rb
Overview
This class helps creating conditions in dsl way, with using helper methods
Instance Method Summary collapse
- #create(&block) ⇒ Object
-
#initialize(name) ⇒ ConditionCreator
constructor
A new instance of ConditionCreator.
- #met?(&block) ⇒ Boolean
- #with_argument ⇒ Object
Methods included from Logging::Logger
Constructor Details
#initialize(name) ⇒ ConditionCreator
Returns a new instance of ConditionCreator.
13 14 15 16 17 |
# File 'lib/kanal/core/conditions/condition_creator.rb', line 13 def initialize(name) @name = name @met_block = nil @with_argument = false end |
Instance Method Details
#create(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kanal/core/conditions/condition_creator.rb', line 19 def create(&block) logger.debug "Attempting to create condition '#{@name}'" instance_eval(&block) unless @name logger.fatal "Attempted to create condition without name" raise "Please provide name for condition" end unless @met_block logger.fatal "Attempted to create condition without met block" raise "Please provide met? block for condition #{@name}" end logger.debug "Creating condition '#{@name}'" Condition.new @name, with_argument: @with_argument, &@met_block end |
#met?(&block) ⇒ Boolean
45 46 47 |
# File 'lib/kanal/core/conditions/condition_creator.rb', line 45 def met?(&block) @met_block = block end |
#with_argument ⇒ Object
41 42 43 |
# File 'lib/kanal/core/conditions/condition_creator.rb', line 41 def with_argument @with_argument = true end |