Class: Ristretta::Event
- Inherits:
-
Object
- Object
- Ristretta::Event
- Defined in:
- lib/ristretta/event.rb
Instance Attribute Summary collapse
-
#event_attrs ⇒ Object
readonly
Returns the value of attribute event_attrs.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
- .create(event_subject, event_type, event_attrs, timestamp = Time.now.to_i) ⇒ Object
- .find(options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(event_attrs, timestamp) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(event_attrs, timestamp) ⇒ Event
Returns a new instance of Event.
5 6 7 8 |
# File 'lib/ristretta/event.rb', line 5 def initialize(event_attrs, ) @event_attrs = JSON.parse(event_attrs) @timestamp = .to_i end |
Instance Attribute Details
#event_attrs ⇒ Object (readonly)
Returns the value of attribute event_attrs.
3 4 5 |
# File 'lib/ristretta/event.rb', line 3 def event_attrs @event_attrs end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/ristretta/event.rb', line 3 def @timestamp end |
Class Method Details
.create(event_subject, event_type, event_attrs, timestamp = Time.now.to_i) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ristretta/event.rb', line 10 def Event.create(event_subject, event_type, event_attrs, = Time.now.to_i) Ristretta.client.zadd(Ristretta.event_key({ event_type: event_type, event_subject: event_subject }), , (event_attrs.merge(timestamp: .to_i)).to_json, nx: true) end |
.find(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ristretta/event.rb', line 17 def Event.find( = {}) raise(Exceptions::SubjectNotSpecified, "event_subject must be specified") if [:event_subject].nil? raise(Exceptions::TypeNotSpecified, "event_type must be specified") if [:event_type].nil? = [:since].to_i = [:until] || Time.now.to_i Ristretta.client.zrangebyscore(Ristretta.event_key(), , , with_scores: true).collect do |event_data| self.new(event_data.first, event_data.last.to_i) end end |