Skip to content

Commit 0b05456

Browse files
committed
Merge branch 'release/v2.7.0'
2 parents d878a5b + bee8f38 commit 0b05456

15 files changed

+488
-177
lines changed

Diff for: .travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
sudo: false
12
language: ruby
23
rvm:
34
- 1.9.3
45
- 2.0
56
- 2.1
67
- 2.2
8+
- 2.3.0-preview1
79
before_install:
810
- rvm @global do gem install bundler

Diff for: CHANGELOG.rdoc

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
== 2.7.0
2+
See https://github.com/ctran/annotate_models/releases/tag/v2.7.0
3+
14
== 2.6.9
25
* Support foreigh key (#241)
36
* Check if model has skip tag in annotate_model_file (#167)

Diff for: Gemfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source 'https://rubygems.org'
22

3-
gem 'rake', '>= 0.8.7', :require => false
4-
gem 'activerecord', '>= 2.3.0', :require => false
3+
gem 'rake', '>= 10.4.2', :require => false
4+
gem 'activerecord', '>= 4.2.5', :require => false
55

66
group :development do
77
gem 'mg', :require => false
@@ -23,6 +23,6 @@ group :development, :test do
2323
end
2424

2525
group :test do
26-
gem 'wrong', '>=0.6.2', :require => false
27-
gem 'files', '>=0.2.1', :require => false
26+
gem 'wrong', :require => false
27+
gem 'files', :require => false
2828
end

Diff for: README.rdoc

+9-6
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.6'
54+
gem 'annotate'
5555

5656
Into Gemfile from Github:
5757

@@ -100,9 +100,7 @@ To remove routes.rb annotations:
100100

101101
annotate --routes --delete
102102

103-
104-
== Configuration
105-
103+
To automatically annotate every time you run +db:migrate+, either run +rails g annotate:install+ or add +Annotate.load_tasks+ to your `Rakefile`. See the [configuration in Rails](#configuration-in-rails) section for more info.
106104

107105
=== Usage Outside of Rails
108106

@@ -112,7 +110,6 @@ or more +--model-dir+ options to inform annotate about the structure of your
112110
project and help it bootstrap and load the relevant code.
113111

114112

115-
116113
== Configuration
117114

118115
If you want to always skip annotations on a particular model, add this string
@@ -130,7 +127,13 @@ default options:
130127
Edit this file to control things like output format, where annotations are
131128
added (top or bottom of file), and in which artifacts.
132129

133-
== Rails Integration
130+
The generated rakefile +lib/tasks/auto_annotate_models.rake+ also contains
131+
`Annotate.load_tasks`. This adds a few rake tasks which duplicate command-line
132+
functionality:
133+
134+
rake annotate_models # Add schema information (as comments) to model and fixture files
135+
rake annotate_routes # Adds the route map to routes.rb
136+
rake remove_annotation # Remove schema information from model and fixture files
134137

135138
By default, once you've generated a configuration file, annotate will be
136139
executed whenever you run +rake db:migrate+ (but only in development mode).

Diff for: annotate.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Gem::Specification.new do |s|
2727

2828
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
2929
s.add_runtime_dependency(%q<rake>, ["~> 10.4"])
30-
s.add_runtime_dependency(%q<activerecord>, [">= 3.2", "<= 4.3"])
30+
s.add_runtime_dependency(%q<activerecord>, [">= 3.2", "< 6.0"])
3131
else
3232
s.add_dependency(%q<rake>, ["~> 10.4"])
33-
s.add_dependency(%q<activerecord>, [">= 3.2", "<= 4.3"])
33+
s.add_dependency(%q<activerecord>, [">= 3.2", "< 6.0"])
3434
end
3535
else
3636
s.add_dependency(%q<rake>, [">= 0.8.7"])
37-
s.add_dependency(%q<activerecord>, [">= 3.2", "<= 4.3"])
37+
s.add_dependency(%q<activerecord>, [">= 3.2", "< 6.0"])
3838
end
3939
end

Diff for: bin/annotate

+20-10
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ require 'optparse'
1818
require 'annotate'
1919
Annotate.bootstrap_rake
2020

21-
target = {
22-
:klass => AnnotateModels,
23-
:task => :do_annotations,
24-
}
2521
has_set_position = {}
22+
target_action = :do_annotations
23+
2624
OptionParser.new do |opts|
2725
opts.banner = "Usage: annotate [options] [model_file]*"
2826

2927
opts.on('-d', '--delete',
3028
"Remove annotations from all model files or the routes.rb file") do
3129

32-
target[:task] = :remove_annotations
30+
target_action = :remove_annotations
3331
end
3432

3533
opts.on('-p', '--position [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
@@ -93,10 +91,7 @@ OptionParser.new do |opts|
9391

9492
opts.on('-r', '--routes',
9593
"Annotate routes.rb with the output of 'rake routes'") do
96-
target = {
97-
:klass => AnnotateRoutes,
98-
:task => :do_annotations
99-
}
94+
ENV['routes'] = 'true'
10095
end
10196

10297
opts.on('-v', '--version',
@@ -129,6 +124,11 @@ OptionParser.new do |opts|
129124
ENV['model_dir'] = dir
130125
end
131126

127+
opts.on('--root-dir dir',
128+
"Annotate files stored within root dir projects, separate multiple dirs with comas") do |dir|
129+
ENV['root_dir'] = dir
130+
end
131+
132132
opts.on('--ignore-model-subdirects',
133133
"Ignore subdirectories of the models directory") do |dir|
134134
ENV['ignore_model_sub_dir'] = "yes"
@@ -178,8 +178,18 @@ OptionParser.new do |opts|
178178
ENV['ignore_columns'] = regex
179179
end
180180

181+
opts.on('--hide-limit-column-types VALUES', "don't show limit for given column types, separated by comas (i.e., `integer,boolean,text`)" ) do |values|
182+
ENV['hide_limit_column_types'] = "#{values}"
183+
end
184+
185+
opts.on('--ignore-unknown-models', "don't display warnings for bad model files" ) do |values|
186+
ENV['ignore_unknown_models'] = "true"
187+
end
188+
181189
end.parse!
182190

183191
options = Annotate.setup_options({ :is_rake => ENV['is_rake'] && !ENV['is_rake'].empty? })
184192
Annotate.eager_load(options)
185-
target[:klass].send(target[:task], options)
193+
194+
AnnotateModels.send(target_action, options) if Annotate.include_models?
195+
AnnotateRoutes.send(target_action, options) if Annotate.include_routes?

Diff for: lib/annotate.rb

+34-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# ActiveSupport 3.x...
88
require 'active_support/hash_with_indifferent_access'
99
require 'active_support/core_ext/object/blank'
10-
rescue Exception => e
10+
rescue Exception
1111
# ActiveSupport 2.x...
1212
require 'active_support/core_ext/hash/indifferent_access'
1313
require 'active_support/core_ext/blank'
@@ -27,32 +27,36 @@ module Annotate
2727
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
2828
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
2929
:timestamp, :exclude_serializers, :classified_sort, :show_foreign_keys,
30+
:exclude_scaffolds, :exclude_controllers, :exclude_helpers, :ignore_unknown_models,
3031
]
3132
OTHER_OPTIONS=[
32-
:ignore_columns
33+
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper, :routes,
34+
:hide_limit_column_types,
3335
]
3436
PATH_OPTIONS=[
35-
:require, :model_dir
37+
:require, :model_dir, :root_dir
3638
]
3739

38-
3940
##
4041
# Set default values that can be overridden via environment variables.
4142
#
4243
def self.set_defaults(options = {})
4344
return if(@has_set_defaults)
4445
@has_set_defaults = true
46+
4547
options = HashWithIndifferentAccess.new(options)
48+
4649
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS, OTHER_OPTIONS].flatten.each do |key|
47-
if(options.has_key?(key))
48-
default_value = if(options[key].is_a?(Array))
50+
if options.has_key?(key)
51+
default_value = if options[key].is_a?(Array)
4952
options[key].join(",")
5053
else
5154
options[key]
5255
end
5356
end
54-
default_value = ENV[key.to_s] if(!ENV[key.to_s].blank?)
55-
ENV[key.to_s] = default_value.to_s
57+
58+
default_value = ENV[key.to_s] if !ENV[key.to_s].blank?
59+
ENV[key.to_s] = default_value.nil? ? nil : default_value.to_s
5660
end
5761
end
5862

@@ -75,13 +79,34 @@ def self.setup_options(options = {})
7579
options[:model_dir] = ['app/models']
7680
end
7781

82+
if(options[:root_dir].empty?)
83+
options[:root_dir] = ['']
84+
end
85+
86+
options[:wrapper_open] ||= options[:wrapper]
87+
options[:wrapper_close] ||= options[:wrapper]
88+
7889
return options
7990
end
8091

92+
def self.reset_options
93+
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS, OTHER_OPTIONS].flatten.each do |key|
94+
ENV[key.to_s] = nil
95+
end
96+
end
97+
8198
def self.skip_on_migration?
8299
ENV['skip_on_db_migrate'] =~ TRUE_RE
83100
end
84101

102+
def self.include_routes?
103+
ENV['routes'] =~ TRUE_RE
104+
end
105+
106+
def self.include_models?
107+
true
108+
end
109+
85110
def self.loaded_tasks=(val); @loaded_tasks = val; end
86111
def self.loaded_tasks; return @loaded_tasks; end
87112

@@ -124,7 +149,7 @@ def self.eager_load(options)
124149
def self.bootstrap_rake
125150
begin
126151
require 'rake/dsl_definition'
127-
rescue Exception => e
152+
rescue Exception
128153
# We might just be on an old version of Rake...
129154
end
130155
require 'rake'

0 commit comments

Comments
 (0)