Skip to content

Commit 723176a

Browse files
committed
Merge branch 'release/v2.6.6'
2 parents 038b13c + 9b72c69 commit 723176a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1145
-133
lines changed

CHANGELOG.rdoc

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
== 2.6.6
2+
* Makes it possible to wrap annotations, #225
3+
* Fix single model generation, #214
4+
* Fix default value for Rails 4.2, #212
5+
* Don't crash on inherited models in subdirectories, #232
6+
* Process model_dir in rake task, #197
7+
18
== 2.6.4
29
* Skip "models/concerns", #194
310
* Fix #173 where annotate says "Nothing to annotate" in rails 4.2

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ end
1313

1414
group :development, :test do
1515
gem 'rspec', :require => false
16-
gem 'guard-rspec', require: false
16+
gem 'guard-rspec', :require => false
17+
gem 'terminal-notifier-guard', :require => false
1718

1819
platforms :mri do
1920
gem 'pry', :require => false

Guardfile

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
1-
# A sample Guardfile
2-
# More info at https://github.com/guard/guard#readme
3-
4-
guard :rspec do
5-
watch(%r{^spec/.+_spec\.rb$})
6-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7-
watch('spec/spec_helper.rb') { "spec" }
8-
9-
# Rails example
10-
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11-
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12-
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"] }
13-
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14-
watch('config/routes.rb') { "spec/routing" }
15-
watch('app/controllers/application_controller.rb') { "spec/controllers" }
16-
17-
# Capybara features specs
18-
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19-
20-
# Turnip features and steps
21-
watch(%r{^spec/acceptance/(.+)\.feature$})
22-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23-
end
241

252

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

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

README.rdoc

100644100755
+23-15
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Also, if you pass the -r option, it'll annotate routes.rb with the output of
5151

5252
Into Gemfile from rubygems.org:
5353

54-
gem 'annotate', ">=2.6.0"
54+
gem 'annotate', '~> 2.6.6'
5555

5656
Into Gemfile from Github:
5757

@@ -86,13 +86,13 @@ To annotate just your models, tests, and factories:
8686

8787
To annotate just your models:
8888

89-
annotate --exclude tests,fixtures,factories
89+
annotate --exclude tests,fixtures,factories,serializers
9090

9191
To annotate routes.rb:
9292

9393
annotate --routes
9494

95-
To remove model/test/fixture/factory annotations:
95+
To remove model/test/fixture/factory/serializer annotations:
9696

9797
annotate --delete
9898

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

140-
'skip_on_db_migrate' => "false",
140+
'skip_on_db_migrate' => 'false',
141141

142142
To:
143143

144-
'skip_on_db_migrate' => "true",
144+
'skip_on_db_migrate' => 'true',
145145

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

155155
Usage: annotate [options] [model_file]*
156156
-d, --delete Remove annotations from all model files or the routes.rb file
157-
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)
158-
--pc, --position-in-class [before|after]
157+
-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)
158+
--pc, --position-in-class [before|top|after|bottom]
159159
Place the annotations at the top (before) or the bottom (after) of the model file
160-
--pf, --position-in-factory [before|after]
160+
--pf, --position-in-factory [before|top|after|bottom]
161161
Place the annotations at the top (before) or the bottom (after) of any factory files
162-
--px, --position-in-fixture [before|after]
162+
--px, --position-in-fixture [before|top|after|bottom]
163163
Place the annotations at the top (before) or the bottom (after) of any fixture files
164-
--pt, --position-in-test [before|after]
164+
--pt, --position-in-test [before|top|after|bottom]
165165
Place the annotations at the top (before) or the bottom (after) of any test files
166-
--pr, --position-in-routes [before|after]
166+
--pr, --position-in-routes [before|top|after|bottom]
167167
Place the annotations at the top (before) or the bottom (after) of the routes.rb file
168+
--ps, --position-in-serializer [before|top|after|bottom]
169+
Place the annotations at the top (before) or the bottom (after) of the serializer files
170+
--w, --wrapper STR Wrap annotation with the text passed as parameter.
171+
If --w option is used, the same text will be used as opening and closing
172+
--wo, --wrapper-open STR Annotation wrapper opening.
173+
--wc, --wrapper-close STR Annotation wrapper closing
168174
-r, --routes Annotate routes.rb with the output of 'rake routes'
169175
-v, --version Show the current version of this gem
170176
-m, --show-migration Include the migration version number in the annotation
171177
-i, --show-indexes List the table's database indexes in the annotation
172178
-s, --simple-indexes Concat the column's related indexes in the annotation
173-
--model-dir dir Annotate model files stored in dir rather than app/models
179+
--model-dir dir Annotate model files stored in dir rather than app/models, separate multiple dirs with comas
174180
--ignore-model-subdirects Ignore subdirectories of the models directory
175181
--sort Sort columns alphabetically, rather than in creation order
176182
-R, --require path Additional file to require before loading models, may be used multiple times
177-
-e [tests,fixtures,factories], Do not annotate fixtures, test files, and/or factories
178-
--exclude
183+
-e [tests,fixtures,factories,serializers],
184+
--exclude Do not annotate fixtures, test files, factories, and/or serializers
179185
-f [bare|rdoc|markdown], Render Schema Infomation as plain/RDoc/Markdown
180186
--format
181187
--force Force new annotations even if there are no changes.
188+
--timestamp Include timestamp in (routes) annotation
182189
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
183-
--timestamp Include an updated time in routes.rb
190+
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`
191+
184192

185193

186194
== Sorting

TODO.rdoc

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

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

87
== TODO (proposed)

annotate.gemspec

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Gem::Specification.new do |s|
88
s.version = Annotate.version
99

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

2827
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29-
s.add_runtime_dependency(%q<rake>, [">= 0.8.7"])
28+
s.add_runtime_dependency(%q<rake>, ["~> 10.4.2", ">= 10.4.2"])
3029
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.0"])
3130
else
3231
s.add_dependency(%q<rake>, [">= 0.8.7"])

bin/annotate

+33-9
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,65 @@ OptionParser.new do |opts|
3232
target[:task] = :remove_annotations
3333
end
3434

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

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

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

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

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

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

75+
opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
76+
"Place the annotations at the top (before) or the bottom (after) of the serializer files") do |p|
77+
ENV['position_in_serializer'] = p
78+
has_set_position['position_in_serializer'] = true
79+
end
80+
81+
opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
82+
'If --w option is used, the same text will be used as opening and closing') do |p|
83+
ENV['wrapper'] = p
84+
end
85+
86+
opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
87+
ENV['wrapper_open'] = p
88+
end
89+
90+
opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
91+
ENV['wrapper_close'] = p
92+
end
93+
7594
opts.on('-r', '--routes',
7695
"Annotate routes.rb with the output of 'rake routes'") do
7796
target = {
@@ -101,7 +120,7 @@ OptionParser.new do |opts|
101120
end
102121

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

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

137+
opts.on('--classified-sort',
138+
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |dir|
139+
ENV['classified_sort'] = "yes"
140+
end
141+
118142
opts.on('-R', '--require path',
119143
"Additional file to require before loading models, may be used multiple times") do |path|
120144
if !ENV['require'].blank?
@@ -124,7 +148,7 @@ OptionParser.new do |opts|
124148
end
125149
end
126150

127-
opts.on('-e', '--exclude [tests,fixtures,factories]', Array, "Do not annotate fixtures, test files, and/or factories") do |exclusions|
151+
opts.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
128152
exclusions ||= %w(tests fixtures factories)
129153
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
130154
end

lib/annotate.rb

100644100755
+11-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ module Annotate
2020
POSITION_OPTIONS=[
2121
:position_in_routes, :position_in_class, :position_in_test,
2222
:position_in_fixture, :position_in_factory, :position,
23+
:position_in_serializer,
2324
]
2425
FLAG_OPTIONS=[
2526
:show_indexes, :simple_indexes, :include_version, :exclude_tests,
2627
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
27-
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :timestamp
28+
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
29+
:timestamp, :exclude_serializers, :classified_sort
2830
]
2931
OTHER_OPTIONS=[
30-
:model_dir, :ignore_columns
32+
:ignore_columns
3133
]
3234
PATH_OPTIONS=[
33-
:require,
35+
:require, :model_dir
3436
]
3537

3638

@@ -41,7 +43,7 @@ def self.set_defaults(options = {})
4143
return if(@has_set_defaults)
4244
@has_set_defaults = true
4345
options = HashWithIndifferentAccess.new(options)
44-
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS].flatten.each do |key|
46+
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS, OTHER_OPTIONS].flatten.each do |key|
4547
if(options.has_key?(key))
4648
default_value = if(options[key].is_a?(Array))
4749
options[key].join(",")
@@ -70,7 +72,7 @@ def self.setup_options(options = {})
7072
end
7173

7274
if(!options[:model_dir])
73-
options[:model_dir] = 'app/models'
75+
options[:model_dir] = ['app/models']
7476
end
7577

7678
return options
@@ -111,8 +113,10 @@ def self.eager_load(options)
111113
klass.eager_load!
112114
end
113115
else
114-
FileList["#{options[:model_dir]}/**/*.rb"].each do |fname|
115-
require File.expand_path(fname)
116+
options[:model_dir].each do |dir|
117+
FileList["#{dir}/**/*.rb"].each do |fname|
118+
require File.expand_path(fname)
119+
end
116120
end
117121
end
118122
end

0 commit comments

Comments
 (0)