Skip to content

Commit

Permalink
Merge branch 'release/v2.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran committed Dec 30, 2015
2 parents d878a5b + bee8f38 commit 0b05456
Show file tree
Hide file tree
Showing 15 changed files with 488 additions and 177 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
sudo: false
language: ruby
rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2
- 2.3.0-preview1
before_install:
- rvm @global do gem install bundler
3 changes: 3 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
== 2.7.0
See https://github.com/ctran/annotate_models/releases/tag/v2.7.0

== 2.6.9
* Support foreigh key (#241)
* Check if model has skip tag in annotate_model_file (#167)
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

gem 'rake', '>= 0.8.7', :require => false
gem 'activerecord', '>= 2.3.0', :require => false
gem 'rake', '>= 10.4.2', :require => false
gem 'activerecord', '>= 4.2.5', :require => false

group :development do
gem 'mg', :require => false
Expand All @@ -23,6 +23,6 @@ group :development, :test do
end

group :test do
gem 'wrong', '>=0.6.2', :require => false
gem 'files', '>=0.2.1', :require => false
gem 'wrong', :require => false
gem 'files', :require => false
end
15 changes: 9 additions & 6 deletions README.rdoc
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.6'
gem 'annotate'

Into Gemfile from Github:

Expand Down Expand Up @@ -100,9 +100,7 @@ To remove routes.rb annotations:

annotate --routes --delete


== Configuration

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.

=== Usage Outside of Rails

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



== Configuration

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

== Rails Integration
The generated rakefile +lib/tasks/auto_annotate_models.rake+ also contains
`Annotate.load_tasks`. This adds a few rake tasks which duplicate command-line
functionality:

rake annotate_models # Add schema information (as comments) to model and fixture files
rake annotate_routes # Adds the route map to routes.rb
rake remove_annotation # Remove schema information from model and fixture files

By default, once you've generated a configuration file, annotate will be
executed whenever you run +rake db:migrate+ (but only in development mode).
Expand Down
6 changes: 3 additions & 3 deletions annotate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Gem::Specification.new do |s|

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, ["~> 10.4"])
s.add_runtime_dependency(%q<activerecord>, [">= 3.2", "<= 4.3"])
s.add_runtime_dependency(%q<activerecord>, [">= 3.2", "< 6.0"])
else
s.add_dependency(%q<rake>, ["~> 10.4"])
s.add_dependency(%q<activerecord>, [">= 3.2", "<= 4.3"])
s.add_dependency(%q<activerecord>, [">= 3.2", "< 6.0"])
end
else
s.add_dependency(%q<rake>, [">= 0.8.7"])
s.add_dependency(%q<activerecord>, [">= 3.2", "<= 4.3"])
s.add_dependency(%q<activerecord>, [">= 3.2", "< 6.0"])
end
end
30 changes: 20 additions & 10 deletions bin/annotate
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ require 'optparse'
require 'annotate'
Annotate.bootstrap_rake

target = {
:klass => AnnotateModels,
:task => :do_annotations,
}
has_set_position = {}
target_action = :do_annotations

OptionParser.new do |opts|
opts.banner = "Usage: annotate [options] [model_file]*"

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

target[:task] = :remove_annotations
target_action = :remove_annotations
end

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

opts.on('-r', '--routes',
"Annotate routes.rb with the output of 'rake routes'") do
target = {
:klass => AnnotateRoutes,
:task => :do_annotations
}
ENV['routes'] = 'true'
end

opts.on('-v', '--version',
Expand Down Expand Up @@ -129,6 +124,11 @@ OptionParser.new do |opts|
ENV['model_dir'] = dir
end

opts.on('--root-dir dir',
"Annotate files stored within root dir projects, separate multiple dirs with comas") do |dir|
ENV['root_dir'] = dir
end

opts.on('--ignore-model-subdirects',
"Ignore subdirectories of the models directory") do |dir|
ENV['ignore_model_sub_dir'] = "yes"
Expand Down Expand Up @@ -178,8 +178,18 @@ OptionParser.new do |opts|
ENV['ignore_columns'] = regex
end

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|
ENV['hide_limit_column_types'] = "#{values}"
end

opts.on('--ignore-unknown-models', "don't display warnings for bad model files" ) do |values|
ENV['ignore_unknown_models'] = "true"
end

end.parse!

options = Annotate.setup_options({ :is_rake => ENV['is_rake'] && !ENV['is_rake'].empty? })
Annotate.eager_load(options)
target[:klass].send(target[:task], options)

AnnotateModels.send(target_action, options) if Annotate.include_models?
AnnotateRoutes.send(target_action, options) if Annotate.include_routes?
43 changes: 34 additions & 9 deletions lib/annotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ActiveSupport 3.x...
require 'active_support/hash_with_indifferent_access'
require 'active_support/core_ext/object/blank'
rescue Exception => e
rescue Exception
# ActiveSupport 2.x...
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/blank'
Expand All @@ -27,32 +27,36 @@ module Annotate
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
:timestamp, :exclude_serializers, :classified_sort, :show_foreign_keys,
:exclude_scaffolds, :exclude_controllers, :exclude_helpers, :ignore_unknown_models,
]
OTHER_OPTIONS=[
:ignore_columns
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper, :routes,
:hide_limit_column_types,
]
PATH_OPTIONS=[
:require, :model_dir
:require, :model_dir, :root_dir
]


##
# Set default values that can be overridden via environment variables.
#
def self.set_defaults(options = {})
return if(@has_set_defaults)
@has_set_defaults = true

options = HashWithIndifferentAccess.new(options)

[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))
if options.has_key?(key)
default_value = if options[key].is_a?(Array)
options[key].join(",")
else
options[key]
end
end
default_value = ENV[key.to_s] if(!ENV[key.to_s].blank?)
ENV[key.to_s] = default_value.to_s

default_value = ENV[key.to_s] if !ENV[key.to_s].blank?
ENV[key.to_s] = default_value.nil? ? nil : default_value.to_s
end
end

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

if(options[:root_dir].empty?)
options[:root_dir] = ['']
end

options[:wrapper_open] ||= options[:wrapper]
options[:wrapper_close] ||= options[:wrapper]

return options
end

def self.reset_options
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS, OTHER_OPTIONS].flatten.each do |key|
ENV[key.to_s] = nil
end
end

def self.skip_on_migration?
ENV['skip_on_db_migrate'] =~ TRUE_RE
end

def self.include_routes?
ENV['routes'] =~ TRUE_RE
end

def self.include_models?
true
end

def self.loaded_tasks=(val); @loaded_tasks = val; end
def self.loaded_tasks; return @loaded_tasks; end

Expand Down Expand Up @@ -124,7 +149,7 @@ def self.eager_load(options)
def self.bootstrap_rake
begin
require 'rake/dsl_definition'
rescue Exception => e
rescue Exception
# We might just be on an old version of Rake...
end
require 'rake'
Expand Down
Loading

0 comments on commit 0b05456

Please sign in to comment.