Sha256: c4af3aff264a686a6cf23ede41caafe5b6db1147c76db6a206ef2c17f0db23d5

Contents?: true

Size: 911 Bytes

Versions: 3

Compression:

Stored size: 911 Bytes

Contents

module Appstats
  class Context < ActiveRecord::Base
    self.table_name = "appstats_contexts"
    establish_connection "appstats_#{Rails.env}" if configurations.keys.include?("appstats_#{Rails.env}")
    
    belongs_to :entry, :class_name => "Appstats::Entry", :foreign_key => "appstats_entry_id"
    attr_accessible :context_key, :context_value
  
    def context_value=(value)
      self[:context_value] = value
      self[:context_int] = nil
      self[:context_float] = nil
      return if value.nil?
      as_int = value.to_i
      as_float = value.to_f
      self[:context_int] = as_int if as_int.to_s == value
      self[:context_float] = as_float if as_float.to_s == value || !self[:context_int].nil?
    end
  
    def to_s
      return "No Context" if context_key.nil? || context_key == ''
      "#{context_key}[]" if context_value.nil?
      "#{context_key}[#{context_value}]"
    end
  
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
appstats-0.25.1 lib/appstats/context.rb
appstats-0.25.0 lib/appstats/context.rb
appstats-0.24.0 lib/appstats/context.rb