Class: Appstats::ContextKey

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/appstats/context_key.rb

Class Method Summary collapse

Class Method Details

.rename(old_key, new_key) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/appstats/context_key.rb', line 8

def self.rename(old_key,new_key)
  sql = ["update appstats_context_keys set name = ?, updated_at = ? where name = ?",new_key,Time.now,old_key]
  Appstats.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]
  Appstats.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]
  Appstats.connection.update(ActiveRecord::Base.send(:sanitize_sql_array, sql))

end

.update_context_keysObject



20
21
22
23
24
25
26
27
28
# File 'lib/appstats/context_key.rb', line 20

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
  Appstats.connection.execute(sql).each do |row| 
    Appstats::ContextKey.create(:name => row[0], :status => 'derived')
    count += 1
  end
  count
end