class RspecProfiling::Collectors::SQL
Public Class Methods
install()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 7 def self.install new.install end
new()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 19 def initialize RspecProfiling.config.db_path ||= 'tmp/rspec_profiling' establish_connection end
reset()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 15 def self.reset new.results.destroy_all end
uninstall()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 11 def self.uninstall new.uninstall end
Public Instance Methods
insert(attributes)
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 49 def insert(attributes) results.create!(attributes.except(:created_at)) end
install()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 24 def install return if prepared? connection.create_table(table) do |t| t.string :branch, index: true t.string :commit_hash, index: true t.datetime :date, index: true t.text :file, index: true t.integer :line_number, index: true t.text :description t.decimal :time, index: true t.string :status, index: true t.text :exception t.integer :query_count, index: true t.decimal :query_time, index:true t.integer :request_count, index: true t.decimal :request_time, index: true t.timestamps null: true end end
results()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 53 def results @results ||= begin establish_connection Result.table_name = table Result.attr_protected if Result.respond_to?(:attr_protected) Result end end
uninstall()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 45 def uninstall connection.drop_table(table) end
Private Instance Methods
connection()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 69 def connection @connection ||= results.connection end
database()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 84 def database RspecProfiling.config.db_path end
establish_connection()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 73 def establish_connection Result.establish_connection( :adapter => 'sqlite3', :database => database ) end
prepared?()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 65 def prepared? connection.table_exists?(table) end
table()
click to toggle source
# File lib/rspec_profiling/collectors/sql.rb, line 80 def table RspecProfiling.config.table_name end