Sha256: 7da3842d74c3c6b5d59d1758aeaf06663a13f97e2555b11db86179e2b907653b

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module Redistat
  module Model
    include Database
    include Options

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


    #
    # statistics store/fetch methods
    #

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

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

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

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


    #
    # options methods
    #

    option_accessor :depth
    option_accessor :scope
    option_accessor :store_event
    option_accessor :hashed_label
    option_accessor :label_indexing

    alias :class_name :scope

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

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


    #
    # resource access methods
    #

    def connection
      db(options[:connection_ref])
    end
    alias :redis :connection

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redistat-0.5.0 lib/redistat/model.rb
redistat-0.4.0 lib/redistat/model.rb