Class: Redistat::Event
- Inherits:
-
Object
- Object
- Redistat::Event
- Defined in:
- lib/redistat/event.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#stats ⇒ Object
Returns the value of attribute stats.
Class Method Summary collapse
Instance Method Summary collapse
- #date ⇒ Object
- #date=(input) ⇒ Object
- #default_options ⇒ Object
- #depth_limit ⇒ Object
-
#initialize(scope, label = nil, date = nil, stats = {}, opts = {}, meta = {}, is_new = true) ⇒ Event
constructor
A new instance of Event.
- #label ⇒ Object
- #label=(input) ⇒ Object
- #label_hash ⇒ Object
- #new? ⇒ Boolean
- #next_id ⇒ Object
- #save ⇒ Object
- #scope ⇒ Object
- #scope=(input) ⇒ Object
Methods included from Options
included, #options, #parse_options, #raw_options
Methods included from Database
Constructor Details
#initialize(scope, label = nil, date = nil, stats = {}, opts = {}, meta = {}, is_new = true) ⇒ Event
Returns a new instance of Event.
20 21 22 23 24 25 26 |
# File 'lib/redistat/event.rb', line 20 def initialize(scope, label = nil, date = nil, stats = {}, opts = {}, = {}, is_new = true) (opts) @key = Key.new(scope, label, date, @options) @stats = stats ||= {} @meta = ||= {} @new = is_new end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/redistat/event.rb', line 6 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/redistat/event.rb', line 7 def key @key end |
#meta ⇒ Object
Returns the value of attribute meta.
10 11 12 |
# File 'lib/redistat/event.rb', line 10 def @meta end |
#stats ⇒ Object
Returns the value of attribute stats.
9 10 11 |
# File 'lib/redistat/event.rb', line 9 def stats @stats end |
Class Method Details
.create(*args) ⇒ Object
86 87 88 |
# File 'lib/redistat/event.rb', line 86 def self.create(*args) self.new(*args).save end |
.find(scope, id) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/redistat/event.rb', line 90 def self.find(scope, id) event = db.hgetall "#{scope}#{KEY_EVENT}#{id}" return nil if event.size == 0 self.new( event["scope"], event["label"], event["date"], JSON.parse(event["stats"]), JSON.parse(event["options"]), JSON.parse(event["meta"]), false ) end |
Instance Method Details
#date ⇒ Object
32 33 34 |
# File 'lib/redistat/event.rb', line 32 def date @key.date end |
#date=(input) ⇒ Object
36 37 38 |
# File 'lib/redistat/event.rb', line 36 def date=(input) @key.date = input end |
#default_options ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/redistat/event.rb', line 12 def { :depth => :hour, :store_event => false, :connection_ref => nil, :enable_grouping => true, :label_indexing => true } end |
#depth_limit ⇒ Object
82 83 84 |
# File 'lib/redistat/event.rb', line 82 def depth_limit @options[:depth] ||= @key.depth end |
#label ⇒ Object
48 49 50 |
# File 'lib/redistat/event.rb', line 48 def label @key.label end |
#label=(input) ⇒ Object
56 57 58 |
# File 'lib/redistat/event.rb', line 56 def label=(input) @key.label = input end |
#label_hash ⇒ Object
52 53 54 |
# File 'lib/redistat/event.rb', line 52 def label_hash @key.label_hash end |
#new? ⇒ Boolean
28 29 30 |
# File 'lib/redistat/event.rb', line 28 def new? @new end |
#next_id ⇒ Object
60 61 62 |
# File 'lib/redistat/event.rb', line 60 def next_id db.incr("#{self.scope}#{KEY_NEXT_ID}") end |
#save ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/redistat/event.rb', line 64 def save return false if !self.new? Summary.update_all(@key, @stats, depth_limit, @options) if @options[:store_event] @id = self.next_id db.hmset("#{self.scope}#{KEY_EVENT}#{@id}", "scope", self.scope, "label", self.label, "date", self.date.to_time.to_s, "stats", self.stats.to_json, "meta", self..to_json, "options", self..to_json) db.sadd("#{self.scope}#{KEY_EVENT_IDS}", @id) end @new = false self end |
#scope ⇒ Object
40 41 42 |
# File 'lib/redistat/event.rb', line 40 def scope @key.scope end |
#scope=(input) ⇒ Object
44 45 46 |
# File 'lib/redistat/event.rb', line 44 def scope=(input) @key.scope = input end |