Class: Huey::Event
- Inherits:
-
Object
- Object
- Huey::Event
- Defined in:
- lib/huey/event.rb
Overview
An event encapsulates logic to send to a group, either at a certain time or arbitrarily
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#at ⇒ Object
Returns the value of attribute at.
-
#group ⇒ Object
Returns the value of attribute group.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(force = false) ⇒ Object
-
#initialize(options) ⇒ Event
constructor
A new instance of Event.
- #should_run? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Event
Returns a new instance of Event.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/huey/event.rb', line 35 def initialize() [:group, :actions].each do |key| raise ArgumentError, "You must supply #{key} to create an event" unless .keys.include?(key) self.instance_variable_set("@#{key}".to_sym, [key]) end self.at = [:at] self.name = [:name] self.group = Huey::Group.find(self.group) unless self.group.is_a?(Huey::Group) Huey::Event.all << self end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
7 8 9 |
# File 'lib/huey/event.rb', line 7 def actions @actions end |
#at ⇒ Object
Returns the value of attribute at.
7 8 9 |
# File 'lib/huey/event.rb', line 7 def at @at end |
#group ⇒ Object
Returns the value of attribute group.
7 8 9 |
# File 'lib/huey/event.rb', line 7 def group @group end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/huey/event.rb', line 7 def name @name end |
Class Method Details
.all ⇒ Object
23 24 25 |
# File 'lib/huey/event.rb', line 23 def self.all @all ||= [] end |
.execute(force = false) ⇒ Object
31 32 33 |
# File 'lib/huey/event.rb', line 31 def self.execute(force = false) Huey::Event.all.collect {|s| s.execute(force)} end |
Instance Method Details
#execute(force = false) ⇒ Object
53 54 55 |
# File 'lib/huey/event.rb', line 53 def execute(force = false) self.group.send(:update, actions) if force || at.nil? || should_run? end |
#should_run? ⇒ Boolean
49 50 51 |
# File 'lib/huey/event.rb', line 49 def should_run? ((Chronic.parse(self.at) - 0.5)..(Chronic.parse(self.at) + 0.5)).cover?(Time.now) end |