Skip to content
Browse files

added support for namespaced/nested models

sort keys when choosing model
  • Loading branch information...
1 parent 8da4454 commit c772819e62a2f608e2c27753aae3b023563c98bb @serevaris serevaris committed with carlosbrando Jun 16, 2010
Showing with 11 additions and 3 deletions.
  1. +11 −3 Support/bin/list_columns.rb
View
14 Support/bin/list_columns.rb
@@ -26,7 +26,7 @@ def run!
options = [
@error || "'#{Inflector.camelize(klass)}' is not an Active Record derived class or was not recognised as a class.",
nil,
- cache.keys.map { |model_name| "Use #{Inflector.camelize(model_name)}..." },
+ cache.keys.map { |model_name| "Use #{Inflector.camelize(model_name)}..." }.sort,
nil,
RELOAD_MESSAGE
].flatten
@@ -87,8 +87,16 @@ def cache_attributes
begin
require "#{TextMate.project_directory}/config/environment"
- Dir.glob(File.join(Rails.root, "app/models/*.rb")) do |file|
- klass = File.basename(file, '.*').camelize.constantize rescue nil
+ Dir.glob(File.join(Rails.root, "app/models/**/*.rb")) do |file|
+ begin
+ klass = file.sub(Rails.root.to_s + '/app/models/', '').sub('.rb', '').camelize.constantize
+ rescue LoadError
+ begin
+ klass = File.basename(file, '.*').camelize.constantize
+ rescue LoadError
+ klass = nil
+ end
+ end
if klass and klass.class.is_a?(Class) and klass.ancestors.include?(ActiveRecord::Base)
_cache[klass.name.underscore] = { :associations => klass.reflections.stringify_keys.keys, :columns => klass.column_names }

0 comments on commit c772819

Please sign in to comment.
Something went wrong with that request. Please try again.