Sha256: eb0189fcc6638645765284c5ce12c294688bdf8c032e23cabc5dd6a4728c30ed

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

module Appstats
  class ContextKey < ActiveRecord::Base
    set_table_name "appstats_context_keys"
    establish_connection "appstats_#{Rails.env}" if configurations.keys.include?("appstats_#{Rails.env}")
    
    attr_accessible :name, :status

    def self.rename(old_key,new_key)
      sql = ["update appstats_context_keys set name = ?, updated_at = ? where name = ?",new_key,Time.now,old_key]
      ActiveRecord::Base.connection.update(ActiveRecord::Base.send(:sanitize_sql_array, sql))

      sql = ["update appstats_contexts set context_key = ?, updated_at = ? where context_key = ?",new_key,Time.now,old_key]
      ActiveRecord::Base.connection.update(ActiveRecord::Base.send(:sanitize_sql_array, sql))

      sql = ["update appstats_action_context_keys set context_key = ?, updated_at = ? where context_key = ?",new_key,Time.now,old_key]
      ActiveRecord::Base.connection.update(ActiveRecord::Base.send(:sanitize_sql_array, sql))

    end

    def self.update_context_keys
      sql = "select distinct(context_key) from appstats_contexts where context_key not in (select name from appstats_context_keys)"
      count = 0
      ActiveRecord::Base.connection.execute(sql).each do |row| 
        Appstats::ContextKey.create(:name => row[0], :status => 'derived')
        count += 1
      end
      count
    end
  
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
appstats-0.22.2 lib/appstats/context_key.rb
appstats-0.22.1 lib/appstats/context_key.rb