Commit 6d7bfc08 by Alex Chaffee

Merge branch 'mrjoy'

* mrjoy: (177 commits) Updating authorship. Resolve conflict between generated rakefile and CLI tool. Minor fixups. Updating readme to be RDoc compliant. fixed a few typos Updating docs to point to this fork. Update docs. Yep, I'm tired. Revert "Version bump to 0.0.0" Version bump to 0.0.0 Changing my mind on project name issue... Making project name match Github project name. Bumping version. Wider type column output, play nice with Rake CLI. Fixing behavior with some model sub-classes, adding skip-annotations feature. Making ActiveSupport dependency float, updating gemspec. Updating change log, readme and TODO list. Update generated .rake file with new options. Renaming bin to avoid conflict with ImageMagick. Accept string or symbol for positions. ... Conflicts: Gemfile Gemfile.lock History.txt README.rdoc Rakefile VERSION.yml annotate.gemspec annotate_models.gemspec lib/annotate/annotate_models.rb lib/tasks/annotate_models.rake lib/tasks/annotate_routes.rake spec/annotate/annotate_models_spec.rb spec/spec_helper.rb todo.txt
parents c52cefe2 b7735703
......@@ -6,3 +6,6 @@ spec/debug.log
pkg/*
dist
Gemfile.lock
*.gem
/.idea/
.rvmrc
rvm use ruby-1.9.2-p290@annotate_models
......@@ -3,9 +3,10 @@ source :rubygems
gem "rake"
group :development do
gem "rspec"
gem "rdoc"
gem "mg"
gem 'activesupport', '>= 2.1.0'
gem "wrong"
gem 'mg'
gem 'rspec'
gem 'wrong'
gem 'rdoc'
end
gem 'activesupport', '>= 3.0.0', :require => nil
......@@ -56,7 +56,7 @@ PLATFORMS
ruby
DEPENDENCIES
activesupport (>= 2.1.0)
activesupport (>= 3.0.0)
mg
rake
rdoc
......
......@@ -20,7 +20,53 @@
* Support FactoryGirl
* Support :change migrations (Rails 3.1)
* Allow models with non-standard capitalization
* Widen type column so we can handle longtexts with chopping things off.
* Skip trying to get list of models from commandline when running via Rake (was
preventing the use of multiple rake tasks in one command if one of them was
db:migrate).
* Add ability to skip annotations for a model by adding
'# -*- SkipSchemaAnnotations' anywhere in the file.
* Don't show column limits for integer and boolean types.
* Add sorting for columns and indexes. (Helpful for out-of-order migration
execution, but use --no-sort if you don't want this.)
* Annotate unit tests in subfolders.
* Add generator to install rakefile that automatically annotates on db:migrate.
* Correct Gemfile to clarify which environments need which gems.
* Add an .rvmrc to facilitate clean development.
* Refactor out ActiveRecord monkey-patch to permit extending without
side-effects.
* Use ObjectSpace to locate models to facilitate handling of models with
non-standard capitalization.
Note that this still requires that the inflector be configured to understand
the special case.
* Shore up test cases a bit.
* Merge against many of the older branches on Github whose functionality is
already reflected to reduce confusion about what is and is not implemented
here.
* Accept String or Symbol for :position (et al) options.
* Rename "annotate" bin to "annotate_models" to avoid conflicting with
ImageMagick.
* Add RDoc output formatting as an option.
* Add Markdown output formatting as an option.
* Add option to force annotation regeneration.
* Add new configuration option for controlling where info is placed in
fixtures/factories.
* Fix for models without tables.
* Fix gemspec generation now that Jeweler looks at Gemfile.
* Fix warning: `NOTE: Gem::Specification#default_executable= is deprecated with
no replacement. It will be removed on or after 2011-10-01.`
* Fix handling of files with no trailing newline when putting annotations at
the end of the file.
== 2.4.2 2009-11-21
* Annotates (spec|test)/factories/<model>_factory.rb files
== 2.4.1 2009-11-20
* Annotates thoughtbot's factory_girl factories (test/factories/<model>_factory.rb)
* Move default annotation position back to top
>>>>>>> mrjoy
== 2.4.0 2009-12-13
......
......@@ -8,6 +8,7 @@ Add a comment summarizing the current schema to the top or bottom of each of you
* Object Daddy exemplars
* Machinist blueprints
* Fabrication fabricators
* Thoughtbot's factory_girl factories, i.e. the (spec|test)/factories/<model>_factory.rb files
The schema comment looks like this:
......@@ -41,7 +42,7 @@ Also, if you pass the -r option, it'll annotate routes.rb with the output of "ra
Into Gemfile from Github:
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
gem 'annotate', :git => 'git://github.com/MrJoy/annotate_models.git'
Into environment gems From rubygems.org:
......@@ -49,8 +50,8 @@ Into environment gems From rubygems.org:
Into environment gems from Github checkout:
git clone git://github.com/ctran/annotate_models.git annotate
cd annotate
git clone git://github.com/MrJoy/annotate_models.git annotate_models
cd annotate_models
rake build
gem install pkg/annotate-*.gem
......@@ -61,60 +62,61 @@ Into environment gems from Github checkout:
To annotate all your models, tests, fixtures, etc.:
cd /path/to/app
annotate
annotate_models
To annotate your models and tests:
annotate --exclude fixtures
annotate_models --exclude fixtures
To annotate just your models:
annotate --exclude tests,fixtures
annotate_models --exclude tests,fixtures
To annotate routes.rb:
annotate -r
annotate_models -r
To automatically annotate after running 'rake db:migrate':
To remove annotations:
[*needs more clarity*] unpack the gem into vendor/plugins, or maybe vendor/gems, or maybe just require tasks/migrate.rake.
annotate_models -d
If you install annotate_models as a plugin, it will automatically
adjust your <tt>rake db:migrate</tt> tasks so that they update the
annotations in your model files for you once the migration is
completed. To get the same behavior from a gem, add the following to
your Rakefile:
To automatically annotate after running 'rake db:migrate', ensure you've added
annotate_models to your Rails project's Gemfile, and run this:
require 'annotate/tasks'
rails g annotate_models:install
To customize the behavior of annotate when it is running as a Rake
task, use the following (in your Rakefile or wherever):
This will produce a .rake file that will ensure annotation happens after
migration (but only in development mode), and provide configuration options
you can use to tailor the output.
ENV['position_in_class'] = "before"
ENV['position_in_fixture'] = "before"
ENV['show_indexes'] = "false"
ENV['include_version'] = "false"
ENV['exclude_tests'] = "false"
ENV['exclude_fixtures'] = "false"
ENV['skip_on_db_migrate'] = "false"
Warning: ImageMagick installs a tool called `annotate` too (if you're using MacPorts it's in `/opt/local/bin/annotate`. So if you see Usage: annotate imagein.jpg imageout.jpg then put `/usr/bin` ahead on the path and you'll get ours instead.
If you want to always skip annotations on a particular model, add this string
anywhere in the file:
# -*- SkipSchemaAnnotations
== OPTIONS
Usage: annotate [options] [model_file]*
Usage: annotate_models [options] [model_file]*
-d, --delete Remove annotations from all model files
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model file
-r, --routes Annotate routes.rb with the output of 'rake routes'
-v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation
-i, --show-indexes List the table's database indexes in the annotation
-s, --simple-indexes Concat the column's related indexes in the annotation
-i, --show-indexes List the indexes for the table in the annotation
-s, --simple-indexes Include information about indexes inline with the relevant column
--model-dir dir Annotate model files stored in dir rather than app/models
--ignore-model-subdirs Ignore sub-directories of the models directory.
-R, --require path Additional files to require before loading models
-e, --exclude [tests,fixtures] Do not annotate fixtures, test files, or both
-e [tests,fixtures] Skip annotation of fixtures/factories/test files
--exclude
-n --no-sort Sort by column creation order rather than alphabetical order
== SORTING
By default, columns will be sorted alphabetically so that the results of
annotation are consistent regardless of what order migrations are executed in.
If you prefer the old behavior, use --no-sort.
== WARNING
......@@ -123,16 +125,16 @@ block in your models if it looks like it was previously added
by annotate models, so you don't want to add additional text
to an automatically created comment block.
* * Back up your model files before using... * *
BACK UP YOUR MODELS BEFORE USING THIS TOOL!
== LINKS
* Factory Girl => http://github.com/thoughtbot/factory_girl (NOT IMPLEMENTED)
* Object Daddy => http://github.com/flogic/object_daddy
* Machinist => http://github.com/notahat/machinist
* Fabrication => http://github.com/paulelliott/fabrication
* SpatialAdapter => http://github.com/pdeffendol/spatial_adapter
* PostgisAdapter => http://github.com/nofxx/postgis_adapter
- Factory Girl: http://github.com/thoughtbot/factory_girl
- Object Daddy: http://github.com/flogic/object_daddy
- Machinist: http://github.com/notahat/machinist
- Fabrication: http://github.com/paulelliott/fabrication
- SpatialAdapter: http://github.com/pdeffendol/spatial_adapter
- PostgisAdapter: http://github.com/nofxx/postgis_adapter
== LICENSE:
......@@ -150,21 +152,23 @@ Maintained by: Alex Chaffee and Cuong Tran
Homepage: http://github.com/ctran/annotate_models
Modifications by:
- Alex Chaffee - http://github.com/alexch - alex@pivotallabs.com
- 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
- Neal Clark - http://github.com/nclark
- Jacqui Maher - http://github.com/jacqui
- Nick Plante - http://github.com/zapnap - http://blog.zerosum.org
- Pedro Visintin - http://github.com/peterpunk - http://www.pedrovisintin.com
- Bob Potter - http://github.com/bpot
- Gavin Montague - http://github.com/govan/
- Alexander Semyonov - http://github.com/rotuka/
- Ian Duggan http://github.com/ijcd/
With help from:
- Alex Chaffee - http://github.com/alexch - alex@pivotallabs.com
- 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
- Neal Clark - http://github.com/nclark
- Jacqui Maher - http://github.com/jacqui
- Nick Plante - http://github.com/zapnap - http://blog.zerosum.org
- Pedro Visintin - http://github.com/peterpunk - http://www.pedrovisintin.com
- Bob Potter - http://github.com/bpot
- Gavin Montague - http://github.com/govan/
- Alexander Semyonov - http://github.com/rotuka/
- Nathan Brazil - http://github.com/bitaxis/
- Ian Duggan http://github.com/ijcd/
- Jon Frisby http://github.com/mrjoy/
and many others that I may have missed to add.
here = File.dirname __FILE__
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake/dsl_definition'
require 'rake'
require "#{here}/lib/annotate"
# want other tests/tasks run by default? Add them to the list
......@@ -25,12 +35,7 @@ begin
rescue LoadError
abort "Please `gem install mg`"
end
MG.new("annotate_models.gemspec")
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
end
MG.new("annotate.gemspec")
task :default => :spec
......@@ -39,18 +44,10 @@ RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = ['spec/*_spec.rb', 'spec/**/*_spec.rb']
end
# FIXME not working yet
RSpec::Core::RakeTask.new(:rcov) do |t|
t.pattern = 'spec/**/*_spec.rb'
t.rcov = true
require 'rdoc/task'
RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "annotated_models #{Annotate.version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
# FIXME warns "already initialized constant Task"
# FIXME throws "uninitialized constant RDoc::VISIBILITIES"
# require 'rdoc/task'
# RDoc::Task.new do |rdoc|
# rdoc.main = "README.rdoc"
# rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
# # require 'lib/annotate'
# # rdoc.title = "annotate #{Annotate.version}"
# end
require './lib/annotate'
Gem::Specification.new do |s|
s.name = %q{annotate_models}
s.version = Annotate.version
s.description = %q{Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.}
s.summary = %q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad"]
s.email = ["alex@stinky.com", "ctran@pragmaquest.com", "x@nofxx.com", "turadg@aleahmad.net"]
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.extra_rdoc_files = ["README.rdoc"]
s.files = %w( README.rdoc VERSION.yml History.txt )
s.files += Dir.glob("lib/**/*")
s.files += Dir.glob("tasks/**/*")
s.files += ["bin/annotate"] # todo: annotate_models
s.homepage = %q{http://github.com/ctran/annotate_models}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{annotate}
s.add_runtime_dependency 'rake' # ?
end
......@@ -2,11 +2,13 @@
require 'optparse'
require 'annotate'
require 'rake/dsl_definition'
require 'rake'
task = :annotate_models
OptionParser.new do |opts|
opts.banner = "Usage: annotate [options] [model_file]*"
opts.banner = "Usage: annotate_models [options] [model_file]*"
opts.on('-d', '--delete',
"Remove annotations from all model files") do
......@@ -48,6 +50,16 @@ OptionParser.new do |opts|
ENV['model_dir'] = dir
end
opts.on('--ignore-model-subdirects',
"Ignore subdirectories of the models directory") do |dir|
ENV['ignore_model_sub_dir'] = "yes"
end
opts.on('-n', '--no-sort',
"Sort columns in creation order rather than alphabetically") do |dir|
ENV['no_sort'] = "yes"
end
opts.on('-R', '--require path',
"Additional files to require before loading models") do |path|
if ENV['require']
......@@ -61,8 +73,17 @@ OptionParser.new do |opts|
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end
opts.on('-f', '--format [bare|rdoc|markdown]', ['bare', 'rdoc', 'markdown'], 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
ENV["format_#{fmt}"] = 'yes'
end
opts.on('--force', 'Force new annotations even if there are no changes.') do |force|
ENV['force'] = 'yes'
end
end.parse!
ENV['is_cli'] = '1'
if Annotate.load_tasks
Rake::Task[task].invoke
else
......
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
require 'yaml'
......@@ -18,6 +16,8 @@ module Annotate
if File.exists?('Rakefile')
require 'rake'
load 'Rakefile'
# Rails 3 wants to load our .rake files for us.
# TODO: selectively do this require on Rails 2.x?
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
return true
else
......
# monkey patches
module ::ActiveRecord
class Base
def self.method_missing(name, *args)
# ignore this, so unknown/unloaded macros won't cause parsing to fail
end
end
end
\ No newline at end of file
Add a .rake file that automatically annotates models when you do a db:migrate
in development mode:
rails generate annotate_models:install
module AnnotateModels
module Generators
class InstallGenerator < Rails::Generators::Base
desc "Copy annotate_models rakefiles for automatic annotation"
source_root File.expand_path('../templates', __FILE__)
# copy rake tasks
def copy_tasks
template "auto_annotate_models.rake", "lib/tasks/auto_annotate_models.rake"
end
end
end
end
\ No newline at end of file
# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if(Rails.env.development?)
task :set_annotation_options do
ENV['position_in_class'] = "before"
ENV['position_in_fixture'] = "before"
ENV['position_in_factory'] = "before"
ENV['show_indexes'] = "true"
ENV['include_version'] = "false"
ENV['exclude_tests'] = "false"
ENV['exclude_fixtures'] = "false"
ENV['ignore_model_sub_dir'] = "false"
ENV['skip_on_db_migrate'] = "false"
ENV['format_rdoc'] = "false"
ENV['format_markdown'] = "false"
ENV['no_sort'] = "false"
ENV['force'] = "false"
end
end
annotate_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
if(!ENV['is_cli'])
task :set_annotation_options
task :annotate_models => :set_annotation_options
end
desc "Add schema information (as comments) to model and fixture files"
task :annotate_models => :environment do
require "#{annotate_lib}/annotate/annotate_models"
require "#{annotate_lib}/annotate/active_record_patch"
true_re = /(true|t|yes|y|1)$/i
options={}
options={ :is_rake => true }
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before'
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before'
options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before'
options[:show_indexes] = ENV['show_indexes'] =~ true_re
options[:simple_indexes] = ENV['simple_indexes'] =~ true_re
options[:model_dir] = ENV['model_dir']
......@@ -14,13 +23,19 @@ task :annotate_models => :environment do
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
options[:exclude_tests] = ENV['exclude_tests'] =~ true_re
options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re
options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
options[:format_markdown] = ENV['format_markdown'] =~ true_re
options[:no_sort] = ENV['no_sort'] =~ true_re
options[:force] = ENV['force'] =~ true_re
AnnotateModels.do_annotations(options)
end
desc "Remove schema information from model and fixture files"
task :remove_annotation => :environment do
require "#{annotate_lib}/annotate/annotate_models"
options={}
require "#{annotate_lib}/annotate/active_record_patch"
options={ :is_rake => true }
options[:model_dir] = ENV['model_dir']
AnnotateModels.remove_annotations(options)
end
desc "Prepends the route map to the top of routes.rb"
task :annotate_routes do
task :annotate_routes => :environment do
annotate_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
require "#{annotate_lib}/annotate/annotate_routes"
AnnotateRoutes.do_annotate
......
--format=specdoc
--colour
\ No newline at end of file
......@@ -9,4 +9,6 @@ end
require "wrong/adapters/rspec"
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'active_support'
require 'active_support/core_ext/string/inflections'
require 'annotate'
TODO
-----
* clean up history
* change default position back to "top" for all annotations
* add "top" and "bottom" as synonyms for "before" and "after"
......@@ -22,4 +23,3 @@ TODO (proposed)
* supply two binaries, named 'annotate' and 'annotate_models', since there's already a unix tool named 'annotate'
* test EVERYTHING
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment