Skip to content

Commit

Permalink
reverting commit that accidentally included class << self refactoring…
Browse files Browse the repository at this point in the history
…. Still

trying to figure this git stuff out ;)
This reverts commit a7e0b8c.
  • Loading branch information
JackDanger committed Mar 9, 2008
1 parent a7e0b8c commit 6def650
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions lib/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def self.annotate_one_file(file_name, info_block)
# on the columns and their types) and put it at the front
# of the model and fixture source files.

def self.annotate(klass, file, header)
def self.annotate(klass, header)
info = get_schema_info(klass, header)

model_file_name = File.join(MODEL_DIR, file)
model_file_name = File.join(MODEL_DIR, klass.name.underscore + ".rb")
annotate_one_file(model_file_name, info)

fixture_file_name = File.join(FIXTURE_DIR, klass.table_name + ".yml")
Expand All @@ -80,7 +80,7 @@ def self.annotate(klass, file, header)
# the underscore or CamelCase versions of model names.
# Otherwise we take all the model files in the
# app/models directory.
def self.get_model_files
def self.get_model_names
models = ARGV.dup
models.shift

Expand All @@ -91,24 +91,12 @@ def self.get_model_files
end
models
end

# Retrieve the classes belonging to the model names we're asked to process
# Check for namespaced models in subdirectories as well as models
# in subdirectories without namespacing.
def self.get_model_class(file)
model = file.gsub(/\.rb$/, '').camelize
parts = model.split('::')
begin
parts.inject(Object) {|klass, part| klass.const_get(part) }
rescue LoadError
Object.const_get(parts.last)
end
end

# We're passed a name of things that might be
# ActiveRecord models. If we can find the class, and
# if its a subclass of ActiveRecord::Base,
# then pas it to the associated block

def self.do_annotations
header = PREFIX.dup
version = ActiveRecord::Migrator.current_version rescue 0
Expand All @@ -117,16 +105,18 @@ def self.do_annotations
end

annotated = []
self.get_model_files.each do |file|
self.get_model_names.each do |m|
class_name = m.sub(/\.rb$/,'').camelize
begin
klass = get_model_class(file)
klass = class_name.split('::').inject(Object){ |klass,part| klass.const_get(part) }
if klass < ActiveRecord::Base && !klass.abstract_class?
annotated << klass
self.annotate(klass, file, header)
annotated << class_name
self.annotate(klass, header)
end
rescue Exception => e
puts "Unable to annotate #{file}: #{e.message}"
puts "Unable to annotate #{class_name}: #{e.message}"
end

end
puts "Annotated #{annotated.join(', ')}"
end
Expand Down

0 comments on commit 6def650

Please sign in to comment.