Skip to content

Commit d1ca354

Browse files
committed
Merge branch 'release/2.6.4'
2 parents c60fa28 + b5bf438 commit d1ca354

Some content is hidden

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

56 files changed

+951
-99
lines changed

CHANGELOG.rdoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
== 2.6.4
2+
* Skip "models/concerns", #194
3+
* Fix #173 where annotate says "Nothing to annotate" in rails 4.2
4+
* Display an error message if not run from the root of the project, #186
5+
* Support rails 4.0 new default test directory, #182
6+
* Add an option to show timestamp in routes "-timestamp", #136
7+
* Skip plain ruby objects if they have the same class name as an ActiveRecord object, #121
8+
19
== 2.6.3
210
* Fix bug of annotate position in routes (#158)
311

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ end
1313

1414
group :development, :test do
1515
gem 'rspec', :require => false
16+
gem 'guard-rspec', require: false
17+
1618
platforms :mri do
1719
gem 'pry', :require => false
1820
gem 'pry-coolline', :require => false

Guardfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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
24+
25+
26+
guard :rspec do
27+
watch(%r{^spec/.+_spec\.rb$})
28+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29+
watch('spec/spec_helper.rb') { "spec" }
30+
31+
# Rails example
32+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
33+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
34+
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"] }
35+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
36+
watch('config/routes.rb') { "spec/routing" }
37+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
38+
39+
# Capybara features specs
40+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
41+
42+
# Turnip features and steps
43+
watch(%r{^spec/acceptance/(.+)\.feature$})
44+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
45+
end
46+

README.rdoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Into Gemfile from rubygems.org:
5454

5555
Into Gemfile from Github:
5656

57-
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
57+
gem 'annotate', github: 'ctran/annotate_models'
5858

5959
Into environment gems from rubygems.org:
6060

@@ -179,6 +179,7 @@ you can do so with a simple environment variable, instead of editing the
179179
--format
180180
--force Force new annotations even if there are no changes.
181181
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
182+
--timestamp Include an updated time in routes.rb
182183

183184

184185
== Sorting

annotate.gemspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# -*- encoding: utf-8 -*-
2-
# stub: annotate 2.6.3 ruby lib
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'annotate/version'
35

46
Gem::Specification.new do |s|
57
s.name = "annotate"
6-
s.version = "2.6.3"
8+
s.version = Annotate.version
79

810
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
911
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad", "Jon Frisby"]

bin/annotate

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/usr/bin/env ruby
2+
3+
unless File.exists?('./Rakefile') || File.exists?('./Gemfile')
4+
abort "Please run annotate from the root of the project."
5+
end
6+
27
require 'rubygems'
38
begin
49
require 'bundler'
@@ -132,6 +137,10 @@ OptionParser.new do |opts|
132137
ENV['force'] = 'yes'
133138
end
134139

140+
opts.on('--timestamp', 'Include timestamp in (routes) annotation') do
141+
ENV['timestamp'] = 'true'
142+
end
143+
135144
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
136145
ENV['trace'] = 'yes'
137146
end
@@ -142,7 +151,6 @@ OptionParser.new do |opts|
142151

143152
end.parse!
144153

145-
146-
options=Annotate.setup_options({ :is_rake => !ENV['is_rake'].blank? })
154+
options = Annotate.setup_options({ :is_rake => ENV['is_rake'] && !ENV['is_rake'].empty? })
147155
Annotate.eager_load(options)
148156
target[:klass].send(target[:task], options)

lib/annotate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Annotate
2222
FLAG_OPTIONS=[
2323
:show_indexes, :simple_indexes, :include_version, :exclude_tests,
2424
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
25-
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
25+
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :timestamp
2626
]
2727
OTHER_OPTIONS=[
2828
:model_dir, :ignore_columns

lib/annotate/annotate_models.rb

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module AnnotateModels
1010
# File.join for windows reverse bar compat?
1111
# I dont use windows, can`t test
1212
UNIT_TEST_DIR = File.join("test", "unit")
13+
MODEL_TEST_DIR = File.join("test", "models") # since rails 4.0
1314
SPEC_MODEL_DIR = File.join("spec", "models")
1415
FIXTURE_TEST_DIR = File.join("test", "fixtures")
1516
FIXTURE_SPEC_DIR = File.join("spec", "fixtures")
@@ -32,6 +33,7 @@ module AnnotateModels
3233

3334
TEST_PATTERNS = [
3435
File.join(UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"),
36+
File.join(MODEL_TEST_DIR, "%MODEL_NAME%_test.rb"),
3537
File.join(SPEC_MODEL_DIR, "%MODEL_NAME%_spec.rb"),
3638
]
3739

@@ -121,7 +123,7 @@ def get_schema_info(klass, header, options = {})
121123
col_type = (col.type || col.sql_type).to_s
122124
if col_type == "decimal"
123125
col_type << "(#{col.precision}, #{col.scale})"
124-
elsif col_type != "spatial"
126+
elsif col_type != "spatial"
125127
if (col.limit)
126128
if col.limit.is_a? Array
127129
attrs << "(#{col.limit.join(', ')})"
@@ -140,7 +142,7 @@ def get_schema_info(klass, header, options = {})
140142
# and print the type and SRID
141143
if col.respond_to?(:geometry_type)
142144
attrs << "#{col.geometry_type}, #{col.srid}"
143-
elsif col.respond_to?(:geometric_type) and col.geometric_type.present?
145+
elsif col.respond_to?(:geometric_type) and col.geometric_type.present?
144146
attrs << "#{col.geometric_type.to_s.downcase}, #{col.srid}"
145147
end
146148

@@ -222,7 +224,7 @@ def annotate_one_file(file_name, info_block, position, options={})
222224
old_header = old_content.match(header_pattern).to_s
223225
new_header = info_block.match(header_pattern).to_s
224226

225-
column_pattern = /^#[\t ]+\w+[\t ]+.+$/
227+
column_pattern = /^#[\t ]+[\w\*`]+[\t ]+.+$/
226228
old_columns = old_header && old_header.scan(column_pattern).sort
227229
new_columns = new_header && new_header.scan(column_pattern).sort
228230

@@ -235,10 +237,10 @@ def annotate_one_file(file_name, info_block, position, options={})
235237
# Replace inline the old schema info with the new schema info
236238
new_content = old_content.sub(PATTERN, info_block + "\n")
237239

238-
if new_content.end_with? (info_block + "\n")
240+
if new_content.end_with?(info_block + "\n")
239241
new_content = old_content.sub(PATTERN, "\n" + info_block)
240242
end
241-
243+
242244
# if there *was* no old schema info (no substitution happened) or :force was passed,
243245
# we simply need to insert it in correct position
244246
if new_content == old_content || options[:force]
@@ -352,7 +354,7 @@ def get_model_files(options)
352354
models = if options[:ignore_model_sub_dir]
353355
Dir["*.rb"]
354356
else
355-
Dir["**/*.rb"]
357+
Dir["**/*.rb"].reject{ |f| f["concerns/"] }
356358
end
357359
end
358360
rescue SystemCallError
@@ -369,21 +371,36 @@ def get_model_files(options)
369371
# Check for namespaced models in subdirectories as well as models
370372
# in subdirectories without namespacing.
371373
def get_model_class(file)
372-
# this is for non-rails projects, which don't get Rails auto-require magic
373-
require File.expand_path("#{model_dir}/#{file}")
374374
model_path = file.gsub(/\.rb$/, '')
375-
get_loaded_model(model_path) || get_loaded_model(model_path.split('/').last)
375+
begin
376+
get_loaded_model(model_path) or raise LoadError.new("cannot load a model from #{file}")
377+
rescue LoadError
378+
# this is for non-rails projects, which don't get Rails auto-require magic
379+
if Kernel.require(File.expand_path("#{model_dir}/#{model_path}"))
380+
retry
381+
elsif model_path.match(/\//)
382+
model_path = model_path.split('/')[1..-1].join('/').to_s
383+
retry
384+
else
385+
raise
386+
end
387+
end
376388
end
377389

378390
# Retrieve loaded model class by path to the file where it's supposed to be defined.
379391
def get_loaded_model(model_path)
380-
ObjectSpace.each_object(::Class).
381-
select do |c|
382-
Class === c and # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
383-
c.ancestors.respond_to?(:include?) and # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
384-
c.ancestors.include?(ActiveRecord::Base)
385-
end.
386-
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
392+
begin
393+
ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.camelize(model_path))
394+
rescue
395+
# Revert to the old way but it is not really robust
396+
ObjectSpace.each_object(::Class).
397+
select do |c|
398+
Class === c and # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
399+
c.ancestors.respond_to?(:include?) and # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
400+
c.ancestors.include?(ActiveRecord::Base)
401+
end.
402+
detect { |c| ActiveSupport::Inflector.underscore(c.to_s) == model_path }
403+
end
387404
end
388405

389406
# We're passed a name of things that might be
@@ -428,7 +445,6 @@ def annotate_model_file(annotated, file, header, options)
428445
end
429446

430447
def remove_annotations(options={})
431-
432448
self.model_dir = options[:model_dir] if options[:model_dir]
433449
deannotated = []
434450
deannotated_klass = false

lib/annotate/annotate_routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def self.do_annotations(options={})
3333
routes_map.shift if(routes_map.first =~ /^\(in \//)
3434

3535
header = [
36-
"#{PREFIX} (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})",
36+
"#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})" : ""),
3737
"#"
3838
] + routes_map.map { |line| "# #{line}".rstrip }
3939

lib/annotate/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Annotate
22
def self.version
3-
'2.6.3'
3+
'2.6.4'
44
end
55
end

lib/generators/annotate/templates/auto_annotate_models.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# NOTE: only doing this in development as some production environments (Heroku)
22
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
33
# NOTE: to have a dev-mode tool do its thing in production.
4-
if(Rails.env.development?)
4+
if Rails.env.development?
55
task :set_annotation_options do
66
# You can override any of these by setting an environment variable of the
77
# same name.

0 commit comments

Comments
 (0)