Module: Redistat::Model

Includes:
Database, Options
Defined in:
lib/redistat/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Options

#default_options, #options, #parse_options, #raw_options

Methods included from Database

#db

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/redistat/model.rb', line 6

def self.included(base)
  base.extend(self)
end

Instance Method Details

#connect_to(opts = {}) ⇒ Object



57
58
59
60
# File 'lib/redistat/model.rb', line 57

def connect_to(opts = {})
  Connection.create(opts.merge(:ref => name))
  options[:connection_ref] = name
end

#connectionObject Also known as: redis

resource access methods



67
68
69
# File 'lib/redistat/model.rb', line 67

def connection
  db(options[:connection_ref])
end

#expire(exp = nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/redistat/model.rb', line 49

def expire(exp = nil)
  if !exp.nil?
    options[:expire] = exp.is_a?(Hash) ? exp : Hash.new(exp)
  else
    options[:expire]
  end
end

#fetch(label, from, till, opts = {}) ⇒ Object Also known as: lookup



20
21
22
# File 'lib/redistat/model.rb', line 20

def fetch(label, from, till, opts = {})
  find(label, from, till, opts).all
end

#find(label, from, till, opts = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/redistat/model.rb', line 25

def find(label, from, till, opts = {})
  Finder.new( { :scope => self.name,
                :label => label,
                :from  => from,
                :till  => till }.merge(options.merge(opts)) )
end

#find_event(event_id) ⇒ Object



32
33
34
# File 'lib/redistat/model.rb', line 32

def find_event(event_id)
  Event.find(self.name, event_id)
end

#nameObject



72
73
74
# File 'lib/redistat/model.rb', line 72

def name
  options[:scope] || (@name ||= self.to_s)
end

#store(label, stats = {}, date = nil, opts = {}, meta = {}) ⇒ Object Also known as: event

statistics store/fetch methods



15
16
17
# File 'lib/redistat/model.rb', line 15

def store(label, stats = {}, date = nil, opts = {}, meta = {})
  Event.new(self.name, label, date, stats, options.merge(opts), meta).save
end