Class: God::Conditions::Lambda
- Inherits:
-
PollCondition
- Object
- Behavior
- God::Condition
- PollCondition
- God::Conditions::Lambda
- Includes:
- ConditionHelper
- Defined in:
- lib/god/conditions/lambda.rb
Instance Attribute Summary collapse
-
#lambda ⇒ Object
can trigger both on: true or false.
-
#times ⇒ Object
can trigger both on: true or false.
-
#trigger_on ⇒ Object
can trigger both on: true or false.
Attributes inherited from PollCondition
Attributes inherited from God::Condition
#info, #notify, #phase, #transition
Attributes inherited from Behavior
Instance Method Summary collapse
-
#initialize ⇒ Lambda
constructor
A new instance of Lambda.
- #prepare ⇒ Object
- #reset ⇒ Object
- #test ⇒ Object
- #valid? ⇒ Boolean
Methods included from ConditionHelper
Methods inherited from PollCondition
Methods inherited from God::Condition
#friendly_name, generate, valid?
Methods inherited from Behavior
#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, #friendly_name, generate
Methods included from God::Configurable
#base_name, complain, #complain, #friendly_name
Constructor Details
#initialize ⇒ Lambda
Returns a new instance of Lambda.
8 9 10 11 12 |
# File 'lib/god/conditions/lambda.rb', line 8 def initialize super self.trigger_on = true self.times = [1, 1] end |
Instance Attribute Details
#lambda ⇒ Object
can trigger both on: true or false
6 7 8 |
# File 'lib/god/conditions/lambda.rb', line 6 def lambda @lambda end |
#times ⇒ Object
can trigger both on: true or false
6 7 8 |
# File 'lib/god/conditions/lambda.rb', line 6 def times @times end |
#trigger_on ⇒ Object
can trigger both on: true or false
6 7 8 |
# File 'lib/god/conditions/lambda.rb', line 6 def trigger_on @trigger_on end |
Instance Method Details
#prepare ⇒ Object
14 15 16 17 18 19 |
# File 'lib/god/conditions/lambda.rb', line 14 def prepare if self.times.kind_of?(Integer) self.times = [self.times, self.times] end @timeline = Timeline.new(self.times[1]) end |
#reset ⇒ Object
21 22 23 |
# File 'lib/god/conditions/lambda.rb', line 21 def reset @timeline.clear end |
#test ⇒ Object
31 32 33 |
# File 'lib/god/conditions/lambda.rb', line 31 def test return timeline_test(self.lambda.call) end |
#valid? ⇒ Boolean
25 26 27 28 29 |
# File 'lib/god/conditions/lambda.rb', line 25 def valid? valid = true valid &= complain("Attribute 'lambda' must be specified", self) if self.lambda.nil? valid end |