Skip to content

Commit

Permalink
Merge branch 'release/v2.6.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran committed Mar 8, 2015
2 parents 038b13c + 9b72c69 commit 723176a
Show file tree
Hide file tree
Showing 67 changed files with 1,145 additions and 133 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
== 2.6.6
* Makes it possible to wrap annotations, #225
* Fix single model generation, #214
* Fix default value for Rails 4.2, #212
* Don't crash on inherited models in subdirectories, #232
* Process model_dir in rake task, #197

== 2.6.4
* Skip "models/concerns", #194
* Fix #173 where annotate says "Nothing to annotate" in rails 4.2
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ end

group :development, :test do
gem 'rspec', :require => false
gem 'guard-rspec', require: false
gem 'guard-rspec', :require => false
gem 'terminal-notifier-guard', :require => false

platforms :mri do
gem 'pry', :require => false
Expand Down
34 changes: 10 additions & 24 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :rspec do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end


guard :rspec do
# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rsspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separetly)
# * 'just' rspec: 'rspec'
guard :rspec, cmd: 'bundle exec rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
Expand All @@ -35,6 +20,7 @@ guard :rspec do
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch('spec/rails_helper.rb') { "spec" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
Expand Down
38 changes: 23 additions & 15 deletions README.rdoc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Also, if you pass the -r option, it'll annotate routes.rb with the output of

Into Gemfile from rubygems.org:

gem 'annotate', ">=2.6.0"
gem 'annotate', '~> 2.6.6'

Into Gemfile from Github:

Expand Down Expand Up @@ -86,13 +86,13 @@ To annotate just your models, tests, and factories:

To annotate just your models:

annotate --exclude tests,fixtures,factories
annotate --exclude tests,fixtures,factories,serializers

To annotate routes.rb:

annotate --routes

To remove model/test/fixture/factory annotations:
To remove model/test/fixture/factory/serializer annotations:

annotate --delete

Expand Down Expand Up @@ -137,11 +137,11 @@ executed whenever you run +rake db:migrate+ (but only in development mode).
If you want to disable this behavior permanently, edit the +.rake+ file and
change:

'skip_on_db_migrate' => "false",
'skip_on_db_migrate' => 'false',

To:

'skip_on_db_migrate' => "true",
'skip_on_db_migrate' => 'true',

If you want to run +rake db:migrate+ as a one-off without running annotate,
you can do so with a simple environment variable, instead of editing the
Expand All @@ -154,33 +154,41 @@ you can do so with a simple environment variable, instead of editing the

Usage: annotate [options] [model_file]*
-d, --delete Remove annotations from all model files or the routes.rb file
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)
--pc, --position-in-class [before|after]
-p, --position [before|top|after|bottom] Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)
--pc, --position-in-class [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of the model file
--pf, --position-in-factory [before|after]
--pf, --position-in-factory [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of any factory files
--px, --position-in-fixture [before|after]
--px, --position-in-fixture [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of any fixture files
--pt, --position-in-test [before|after]
--pt, --position-in-test [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of any test files
--pr, --position-in-routes [before|after]
--pr, --position-in-routes [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of the routes.rb file
--ps, --position-in-serializer [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of the serializer files
--w, --wrapper STR Wrap annotation with the text passed as parameter.
If --w option is used, the same text will be used as opening and closing
--wo, --wrapper-open STR Annotation wrapper opening.
--wc, --wrapper-close STR Annotation wrapper closing
-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
--model-dir dir Annotate model files stored in dir rather than app/models
--model-dir dir Annotate model files stored in dir rather than app/models, separate multiple dirs with comas
--ignore-model-subdirects Ignore subdirectories of the models directory
--sort Sort columns alphabetically, rather than in creation order
-R, --require path Additional file to require before loading models, may be used multiple times
-e [tests,fixtures,factories], Do not annotate fixtures, test files, and/or factories
--exclude
-e [tests,fixtures,factories,serializers],
--exclude Do not annotate fixtures, test files, factories, and/or serializers
-f [bare|rdoc|markdown], Render Schema Infomation as plain/RDoc/Markdown
--format
--force Force new annotations even if there are no changes.
--timestamp Include timestamp in (routes) annotation
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
--timestamp Include an updated time in routes.rb
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`



== Sorting
Expand Down
1 change: 0 additions & 1 deletion TODO.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

- clean up history
- change default position back to "top" for all annotations
- add "top" and "bottom" as synonyms for "before" and "after"
- change 'exclude' to 'only' (double negatives are not unconfusing)

== TODO (proposed)
Expand Down
5 changes: 2 additions & 3 deletions annotate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Gem::Specification.new do |s|
s.version = Annotate.version

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad", "Jon Frisby"]
s.date = "2014-06-16"
s.authors = ["Alex Chaffee", "Cuong Tran", "Marcos Piccinini", "Turadg Aleahmad", "Jon Frisby"]
s.description = "Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema."
s.email = ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"]
s.executables = ["annotate"]
Expand All @@ -26,7 +25,7 @@ Gem::Specification.new do |s|
s.specification_version = 4

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, [">= 0.8.7"])
s.add_runtime_dependency(%q<rake>, ["~> 10.4.2", ">= 10.4.2"])
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.0"])
else
s.add_dependency(%q<rake>, [">= 0.8.7"])
Expand Down
42 changes: 33 additions & 9 deletions bin/annotate
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,65 @@ OptionParser.new do |opts|
target[:task] = :remove_annotations
end

opts.on('-p', '--position [before|after]', ['before', 'after'],
opts.on('-p', '--position [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)") do |p|
ENV['position'] = p
[
'position_in_class','position_in_factory','position_in_fixture','position_in_test', 'position_in_routes'
'position_in_class','position_in_factory','position_in_fixture','position_in_test', 'position_in_routes', 'position_in_serializer'
].each do |key|
ENV[key] = p unless(has_set_position[key])
end
end

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

opts.on('--pf', '--position-in-factory [before|after]', ['before', 'after'],
opts.on('--pf', '--position-in-factory [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of any factory files") do |p|
ENV['position_in_factory'] = p
has_set_position['position_in_factory'] = true
end

opts.on('--px', '--position-in-fixture [before|after]', ['before', 'after'],
opts.on('--px', '--position-in-fixture [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of any fixture files") do |p|
ENV['position_in_fixture'] = p
has_set_position['position_in_fixture'] = true
end

opts.on('--pt', '--position-in-test [before|after]', ['before', 'after'],
opts.on('--pt', '--position-in-test [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of any test files") do |p|
ENV['position_in_test'] = p
has_set_position['position_in_test'] = true
end

opts.on('--pr', '--position-in-routes [before|after]', ['before', 'after'],
opts.on('--pr', '--position-in-routes [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of the routes.rb file") do |p|
ENV['position_in_routes'] = p
has_set_position['position_in_routes'] = true
end

opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of the serializer files") do |p|
ENV['position_in_serializer'] = p
has_set_position['position_in_serializer'] = true
end

opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
'If --w option is used, the same text will be used as opening and closing') do |p|
ENV['wrapper'] = p
end

opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
ENV['wrapper_open'] = p
end

opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
ENV['wrapper_close'] = p
end

opts.on('-r', '--routes',
"Annotate routes.rb with the output of 'rake routes'") do
target = {
Expand Down Expand Up @@ -101,7 +120,7 @@ OptionParser.new do |opts|
end

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

Expand All @@ -115,6 +134,11 @@ OptionParser.new do |opts|
ENV['sort'] = "yes"
end

opts.on('--classified-sort',
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |dir|
ENV['classified_sort'] = "yes"
end

opts.on('-R', '--require path',
"Additional file to require before loading models, may be used multiple times") do |path|
if !ENV['require'].blank?
Expand All @@ -124,7 +148,7 @@ OptionParser.new do |opts|
end
end

opts.on('-e', '--exclude [tests,fixtures,factories]', Array, "Do not annotate fixtures, test files, and/or factories") do |exclusions|
opts.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= %w(tests fixtures factories)
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end
Expand Down
18 changes: 11 additions & 7 deletions lib/annotate.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ module Annotate
POSITION_OPTIONS=[
:position_in_routes, :position_in_class, :position_in_test,
:position_in_fixture, :position_in_factory, :position,
:position_in_serializer,
]
FLAG_OPTIONS=[
:show_indexes, :simple_indexes, :include_version, :exclude_tests,
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :timestamp
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
:timestamp, :exclude_serializers, :classified_sort
]
OTHER_OPTIONS=[
:model_dir, :ignore_columns
:ignore_columns
]
PATH_OPTIONS=[
:require,
:require, :model_dir
]


Expand All @@ -41,7 +43,7 @@ def self.set_defaults(options = {})
return if(@has_set_defaults)
@has_set_defaults = true
options = HashWithIndifferentAccess.new(options)
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS].flatten.each do |key|
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS, OTHER_OPTIONS].flatten.each do |key|
if(options.has_key?(key))
default_value = if(options[key].is_a?(Array))
options[key].join(",")
Expand Down Expand Up @@ -70,7 +72,7 @@ def self.setup_options(options = {})
end

if(!options[:model_dir])
options[:model_dir] = 'app/models'
options[:model_dir] = ['app/models']
end

return options
Expand Down Expand Up @@ -111,8 +113,10 @@ def self.eager_load(options)
klass.eager_load!
end
else
FileList["#{options[:model_dir]}/**/*.rb"].each do |fname|
require File.expand_path(fname)
options[:model_dir].each do |dir|
FileList["#{dir}/**/*.rb"].each do |fname|
require File.expand_path(fname)
end
end
end
end
Expand Down
Loading

0 comments on commit 723176a

Please sign in to comment.