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



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

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

#connectionObject Also known as: redis

resource access methods



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

def connection
  db(options[:connection_ref])
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



64
65
66
# File 'lib/redistat/model.rb', line 64

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