1
1
#!/usr/bin/env ruby
2
2
3
- unless File . exists ?( './Rakefile' ) || File . exists ?( './Gemfile' )
4
- abort " Please run annotate from the root of the project."
3
+ unless File . exist ?( './Rakefile' ) || File . exist ?( './Gemfile' )
4
+ abort ' Please run annotate from the root of the project.'
5
5
end
6
6
7
7
require 'rubygems'
@@ -20,58 +20,55 @@ Annotate.bootstrap_rake
20
20
21
21
has_set_position = { }
22
22
target_action = :do_annotations
23
+ positions = %w( before top after bottom )
23
24
24
25
OptionParser . new do |opts |
25
- opts . banner = "Usage: annotate [options] [model_file]*"
26
-
27
- opts . on ( '-d' , '--delete' ,
28
- "Remove annotations from all model files or the routes.rb file" ) do
26
+ opts . banner = 'Usage: annotate [options] [model_file]*'
29
27
28
+ opts . on ( '-d' , '--delete' , 'Remove annotations from all model files or the routes.rb file' ) do
30
29
target_action = :remove_annotations
31
30
end
32
31
33
- opts . on ( '-p' , '--position [before|top|after|bottom]' , [ 'before' , 'top' , 'after' , 'bottom' ] ,
34
- " Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)" ) do |p |
32
+ opts . on ( '-p' , '--position [before|top|after|bottom]' , positions ,
33
+ ' Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)' ) do |p |
35
34
ENV [ 'position' ] = p
36
- [
37
- 'position_in_class' , 'position_in_factory' , 'position_in_fixture' , 'position_in_test' , 'position_in_routes' , 'position_in_serializer'
38
- ] . each do |key |
35
+ %w( position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer ) . each do |key |
39
36
ENV [ key ] = p unless ( has_set_position [ key ] )
40
37
end
41
38
end
42
39
43
- opts . on ( '--pc' , '--position-in-class [before|top|after|bottom]' , [ 'before' , 'top' , 'after' , 'bottom' ] ,
44
- " Place the annotations at the top (before) or the bottom (after) of the model file" ) do |p |
40
+ opts . on ( '--pc' , '--position-in-class [before|top|after|bottom]' , positions ,
41
+ ' Place the annotations at the top (before) or the bottom (after) of the model file' ) do |p |
45
42
ENV [ 'position_in_class' ] = p
46
43
has_set_position [ 'position_in_class' ] = true
47
44
end
48
45
49
- opts . on ( '--pf' , '--position-in-factory [before|top|after|bottom]' , [ 'before' , 'top' , 'after' , 'bottom' ] ,
50
- " Place the annotations at the top (before) or the bottom (after) of any factory files" ) do |p |
46
+ opts . on ( '--pf' , '--position-in-factory [before|top|after|bottom]' , positions ,
47
+ ' Place the annotations at the top (before) or the bottom (after) of any factory files' ) do |p |
51
48
ENV [ 'position_in_factory' ] = p
52
49
has_set_position [ 'position_in_factory' ] = true
53
50
end
54
51
55
- opts . on ( '--px' , '--position-in-fixture [before|top|after|bottom]' , [ 'before' , 'top' , 'after' , 'bottom' ] ,
56
- " Place the annotations at the top (before) or the bottom (after) of any fixture files" ) do |p |
52
+ opts . on ( '--px' , '--position-in-fixture [before|top|after|bottom]' , positions ,
53
+ ' Place the annotations at the top (before) or the bottom (after) of any fixture files' ) do |p |
57
54
ENV [ 'position_in_fixture' ] = p
58
55
has_set_position [ 'position_in_fixture' ] = true
59
56
end
60
57
61
- opts . on ( '--pt' , '--position-in-test [before|top|after|bottom]' , [ 'before' , 'top' , 'after' , 'bottom' ] ,
62
- " Place the annotations at the top (before) or the bottom (after) of any test files" ) do |p |
58
+ opts . on ( '--pt' , '--position-in-test [before|top|after|bottom]' , positions ,
59
+ ' Place the annotations at the top (before) or the bottom (after) of any test files' ) do |p |
63
60
ENV [ 'position_in_test' ] = p
64
61
has_set_position [ 'position_in_test' ] = true
65
62
end
66
63
67
- opts . on ( '--pr' , '--position-in-routes [before|top|after|bottom]' , [ 'before' , 'top' , 'after' , 'bottom' ] ,
68
- " Place the annotations at the top (before) or the bottom (after) of the routes.rb file" ) do |p |
64
+ opts . on ( '--pr' , '--position-in-routes [before|top|after|bottom]' , positions ,
65
+ ' Place the annotations at the top (before) or the bottom (after) of the routes.rb file' ) do |p |
69
66
ENV [ 'position_in_routes' ] = p
70
67
has_set_position [ 'position_in_routes' ] = true
71
68
end
72
69
73
- opts . on ( '--ps' , '--position-in-serializer [before|top|after|bottom]' , [ 'before' , 'top' , 'after' , 'bottom' ] ,
74
- " Place the annotations at the top (before) or the bottom (after) of the serializer files" ) do |p |
70
+ opts . on ( '--ps' , '--position-in-serializer [before|top|after|bottom]' , positions ,
71
+ ' Place the annotations at the top (before) or the bottom (after) of the serializer files' ) do |p |
75
72
ENV [ 'position_in_serializer' ] = p
76
73
has_set_position [ 'position_in_serializer' ] = true
77
74
end
@@ -89,34 +86,32 @@ OptionParser.new do |opts|
89
86
ENV [ 'wrapper_close' ] = p
90
87
end
91
88
92
- opts . on ( '-r' , '--routes' ,
93
- "Annotate routes.rb with the output of 'rake routes'" ) do
89
+ opts . on ( '-r' , '--routes' , "Annotate routes.rb with the output of 'rake routes'" ) do
94
90
ENV [ 'routes' ] = 'true'
95
91
end
96
92
97
93
opts . on ( '-v' , '--version' ,
98
- " Show the current version of this gem" ) do
94
+ ' Show the current version of this gem' ) do
99
95
puts "annotate v#{ Annotate . version } " ; exit
100
96
end
101
97
102
- opts . on ( '-m' , '--show-migration' ,
103
- "Include the migration version number in the annotation" ) do
104
- ENV [ 'include_version' ] = "yes"
98
+ opts . on ( '-m' , '--show-migration' , 'Include the migration version number in the annotation' ) do
99
+ ENV [ 'include_version' ] = 'yes'
105
100
end
106
101
107
102
opts . on ( '-k' , '--show-foreign-keys' ,
108
103
"List the table's foreign key constraints in the annotation" ) do
109
- ENV [ 'show_foreign_keys' ] = " yes"
104
+ ENV [ 'show_foreign_keys' ] = ' yes'
110
105
end
111
106
112
107
opts . on ( '-i' , '--show-indexes' ,
113
108
"List the table's database indexes in the annotation" ) do
114
- ENV [ 'show_indexes' ] = " yes"
109
+ ENV [ 'show_indexes' ] = ' yes'
115
110
end
116
111
117
112
opts . on ( '-s' , '--simple-indexes' ,
118
113
"Concat the column's related indexes in the annotation" ) do
119
- ENV [ 'simple_indexes' ] = " yes"
114
+ ENV [ 'simple_indexes' ] = ' yes'
120
115
end
121
116
122
117
opts . on ( '--model-dir dir' ,
@@ -131,17 +126,17 @@ OptionParser.new do |opts|
131
126
132
127
opts . on ( '--ignore-model-subdirects' ,
133
128
"Ignore subdirectories of the models directory" ) do |dir |
134
- ENV [ 'ignore_model_sub_dir' ] = " yes"
129
+ ENV [ 'ignore_model_sub_dir' ] = ' yes'
135
130
end
136
131
137
132
opts . on ( '--sort' ,
138
133
"Sort columns alphabetically, rather than in creation order" ) do |dir |
139
- ENV [ 'sort' ] = " yes"
134
+ ENV [ 'sort' ] = ' yes'
140
135
end
141
136
142
137
opts . on ( '--classified-sort' ,
143
138
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns" ) do |dir |
144
- ENV [ 'classified_sort' ] = " yes"
139
+ ENV [ 'classified_sort' ] = ' yes'
145
140
end
146
141
147
142
opts . on ( '-R' , '--require path' ,
@@ -155,10 +150,10 @@ OptionParser.new do |opts|
155
150
156
151
opts . on ( '-e' , '--exclude [tests,fixtures,factories,serializers]' , Array , "Do not annotate fixtures, test files, factories, and/or serializers" ) do |exclusions |
157
152
exclusions ||= %w( tests fixtures factories )
158
- exclusions . each { |exclusion | ENV [ "exclude_#{ exclusion } " ] = " yes" }
153
+ exclusions . each { |exclusion | ENV [ "exclude_#{ exclusion } " ] = ' yes' }
159
154
end
160
155
161
- opts . on ( '-f' , '--format [bare|rdoc|markdown]' , [ ' bare' , ' rdoc' , ' markdown' ] , 'Render Schema Infomation as plain/RDoc/Markdown' ) do |fmt |
156
+ opts . on ( '-f' , '--format [bare|rdoc|markdown]' , %w( bare rdoc markdown ) , 'Render Schema Infomation as plain/RDoc/Markdown' ) do |fmt |
162
157
ENV [ "format_#{ fmt } " ] = 'yes'
163
158
end
164
159
@@ -186,8 +181,8 @@ OptionParser.new do |opts|
186
181
ENV [ 'hide_limit_column_types' ] = "#{ values } "
187
182
end
188
183
189
- opts . on ( '--ignore-unknown-models' , "don't display warnings for bad model files" ) do |values |
190
- ENV [ 'ignore_unknown_models' ] = " true"
184
+ opts . on ( '--ignore-unknown-models' , "don't display warnings for bad model files" ) do |_values |
185
+ ENV [ 'ignore_unknown_models' ] = ' true'
191
186
end
192
187
193
188
end . parse!
0 commit comments