Sha256: 551d838c35308ee192c19a296c5234690f9bf9c7b9f663dca44cad8de2b69bed

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module Redistat
  module Model
    
    def self.included(base)
      base.extend(self)
    end
    
    def store(label, stats = {}, date = nil, meta = {}, opts = {})
      Event.new(name, label, date, stats, options.merge(opts), meta).save
    end
    alias :event :store
    
    def fetch(label, from, till, opts = {})
      Finder.find({
        :scope => name,
        :label => label,
        :from  => from,
        :till  => till
      }.merge(options.merge(opts)))
    end
    alias :lookup :fetch
    
    def hashed_label(boolean = nil)
      if !boolean.nil?
        options[:hashed_label] = boolean
      else
        options[:hashed_label] || nil
      end
    end
    
    def depth(depth = nil)
      if !depth.nil?
        options[:depth] = depth
      else
        options[:depth] || nil
      end
    end
    
    def store_event(boolean = nil)
      if !boolean.nil?
        options[:store_event] = boolean
      else
        options[:store_event] || nil
      end
    end
    
    def options
      @options ||= {}
    end
    
    private
    
    def name
      @name ||= self.to_s
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redistat-0.0.4 lib/redistat/model.rb
redistat-0.0.3 lib/redistat/model.rb