Skip to content

Commit

Permalink
* Cleaning up documentation getting ready to relase v2.1
Browse files Browse the repository at this point in the history
Merge branch 'master' of git://github.com/nclark/annotate_models

* 'master' of git://github.com/nclark/annotate_models:
  adding option to not annotate tests or fixtures
  • Loading branch information
alexch committed Oct 18, 2009
2 parents 3738206 + d430889 commit 68f951d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 12 deletions.
10 changes: 10 additions & 0 deletions History.txt
@@ -1,3 +1,13 @@
== 2.1 2009-10-18

* New options
* -R to require additional files before loading the models
* -i to show database indexes in annotations
* -e to exclude annotating tests or fixtures
* -m to include the migration version number in the annotation
* --model-dir to annotate model files stored a different place than app/models
* Ignore unknown macros ('acts_as_whatever')

== 2.0 2009-02-03

* Add annotate_models plugin fork additions
Expand Down
15 changes: 13 additions & 2 deletions README.rdoc
Expand Up @@ -51,11 +51,19 @@ From github:

== Usage

To annotate all your models:
To annotate all your models, tests, and fixtures:

cd /path/to/app
annotate

To annotate your models and tests:

annotate --exclude fixtures

To annotate just your models:

annotate --exclude tests,fixtures

To annotate routes.rb:

annotate -r
Expand All @@ -70,6 +78,8 @@ More options:
-m, --show-migration Include the migration version number in the annotation
-i, --show-indexes List the table's database indexes in the annotation
--model-dir dir Annotate model files stored in dir rather than app/models
-R, --require path Additional files to require before loading models
-e, --exclude [tests,fixtures] Do not annotate fixtures, test files, or both

== LICENSE:

Expand All @@ -84,11 +94,12 @@ Original code by:
Modifications by:

- Alex Chaffee - http://github.com/alexch - alex@pivotallabs.com
- Cuong Tran - http://github.com/ctran
- Cuong Tran - http://github.com/ctran - ctran@pragmaquest.com
- Jack Danger - http://github.com/JackDanger
- Michael Bumann - http://github.com/bumi
- Henrik Nyh - http://github.com/henrik
- Marcos Piccinini - http://github.com/nofxx

and many others that I may have missed to add.

Primary maintainers: Cuong Tran and Alex Chaffee
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -25,4 +25,4 @@ require 'newgem/tasks' # load /tasks/*.rake
Dir['tasks/**/*.rake'].each { |t| load t }

# TODO - want other tests/tasks run by default? Add them to the list
# task :default => [:spec, :features]
task :default => [:spec, :features]
2 changes: 1 addition & 1 deletion annotate.gemspec
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{annotate}
s.version = "2.0.2"
s.version = "2.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran"]
Expand Down
15 changes: 14 additions & 1 deletion bin/annotate 100644 → 100755
Expand Up @@ -7,34 +7,42 @@ task = :annotate_models

OptionParser.new do |opts|
opts.banner = "Usage: annotate [options]"

opts.on('-d', '--delete',
"Remove annotations from all model files") do
task = :remove_annotation
end

opts.on('-p', '--position [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
ENV['position'] = p
end

opts.on('-r', '--routes',
"Annotate routes.rb with the output of 'rake routes'") do
task = :annotate_routes
end

opts.on('-v', '--version',
"Show the current version of this gem") do
puts "Annotate v#{Annotate::VERSION}"; exit
puts "annotate v#{Annotate::VERSION}"; exit
end

opts.on('-m', '--show-migration',
"Include the migration version number in the annotation") do
ENV['include_version'] = "yes"
end

opts.on('-i', '--show-indexes',
"List the table's database indexes in the annotation") do
ENV['show_indexes'] = "yes"
end

opts.on('--model-dir dir',
"Annotate model files stored in dir rather than app/models") do |dir|
ENV['model_dir'] = dir
end

opts.on('-R', '--require path',
"Additional files to require before loading models") do |path|
if ENV['require']
Expand All @@ -43,6 +51,11 @@ OptionParser.new do |opts|
ENV['require'] = path
end
end

opts.on('-e', '--exclude [tests,fixtures]', Array, "Do not annotate fixtures, test files, or both") do |exclusions|
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end

end.parse!

if Annotate.load_tasks
Expand Down
2 changes: 1 addition & 1 deletion lib/annotate.rb
Expand Up @@ -2,7 +2,7 @@
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

module Annotate
VERSION = '2.0.2'
VERSION = '2.1'

def self.load_tasks
if File.exists?('Rakefile')
Expand Down
19 changes: 13 additions & 6 deletions lib/annotate/annotate_models.rb
Expand Up @@ -148,17 +148,24 @@ def annotate(klass, file, header,options={})
annotated = true
end

annotate_tests(info, model_name) unless ENV['exclude_tests']
annotate_fixtures(info, klass, options) unless ENV['exclude_fixtures']
annotated
end

def annotate_tests(info, model_name)
[
File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"), # test
File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"), # spec
File.join(EXEMPLARS_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"), # test
File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"), # spec
File.join(EXEMPLARS_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
].each { |file| annotate_one_file(file, info) }
end

def annotate_fixtures(info, klass, options)
FIXTURE_DIRS.each do |dir|
fixture_file_name = File.join(dir,klass.table_name + ".yml")
fixture_file_name = File.join(dir, klass.table_name + ".yml")
annotate_one_file(fixture_file_name, info, options.merge(:position=>(options[:position_in_fixture] || options[:position]))) if File.exist?(fixture_file_name)
end
annotated
end

# Return a list of the model files to annotate. If we have
Expand Down Expand Up @@ -250,7 +257,7 @@ def remove_annotations(options={})

model_file_name = File.join(model_dir, file)
remove_annotation_of_file(model_file_name)

FIXTURE_DIRS.each do |dir|
fixture_file_name = File.join(dir,klass.table_name + ".yml")
remove_annotation_of_file(fixture_file_name) if File.exist?(fixture_file_name)
Expand Down

0 comments on commit 68f951d

Please sign in to comment.