Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added resque blocks to allow some useful output even when there are s…

…ome errors
  • Loading branch information...
commit aa91ad3b88559ad97f6f7e8c5a2042caedbceba1 1 parent 1bc8703
Kali Donovan authored
Showing with 21 additions and 11 deletions.
  1. +1 −1  README.textile
  2. +20 −10 lib/indexer.rb
View
2  README.textile
@@ -2,7 +2,7 @@ h1. Rails Indexes
Rails indexes is a small package of 2 rake tasks that scan your application models and displays a list of columns that _probably_ should be indexed.
-note: there should be mode fields depending on your application design and custom queries.
+Note: there may be more fields depending on your application design and custom queries.
h2. Installation
View
30 lib/indexer.rb
@@ -160,6 +160,8 @@ def self.scan_finds
# Check line for find* methods (include find_all, find_by and just find)
def self.check_line_for_find_indexes(file_name, line)
+ # TODO: Chokes on finders called on associations, e.g. current_user.widgets.find( params[:widget_id] )
+
# TODO: Assumes that you have a called on #find. you can actually call #find without a caller in a model code. ex:
# def something
# find(self.id)
@@ -174,16 +176,20 @@ def self.check_line_for_find_indexes(file_name, line)
model_name, column_names, options = matches[2], matches[7], matches[8]
- # if the finder class is "self" or empty (can be a simple "find()" in a model)
- if model_name == "self" || model_name.blank?
- model_name = File.basename(file_name).sub(/\.rb$/,'').camelize
- table_name = model_name.constantize.table_name
- else
- if model_name.respond_to?(:constantize)
- if model_name.constantize.respond_to?(:table_name)
- table_name = model_name.constantize.table_name
+ begin
+ # if the finder class is "self" or empty (can be a simple "find()" in a model)
+ if model_name == "self" || model_name.blank?
+ model_name = File.basename(file_name).sub(/\.rb$/,'').camelize
+ table_name = model_name.constantize.table_name
+ else
+ if model_name.respond_to?(:constantize)
+ if model_name.constantize.respond_to?(:table_name)
+ table_name = model_name.constantize.table_name
+ end
end
end
+ rescue
+ puts "ERROR: #{e} in #{line}"
end
# Check that all prerequisites are met
@@ -213,8 +219,12 @@ def self.check_line_for_find_indexes(file_name, line)
end
def self.key_exists?(table,key_columns)
- result = (key_columns.to_a - ActiveRecord::Base.connection.indexes(table).map { |i| i.columns }.flatten)
- result.empty?
+ begin
+ result = (key_columns.to_a - ActiveRecord::Base.connection.indexes(table).map { |i| i.columns }.flatten)
+ result.empty?
+ rescue Exception => e
+ puts "ERROR: #{e} for table #{table}"
+ end
end
def self.simple_migration
Please sign in to comment.
Something went wrong with that request. Please try again.