Skip to content

Commit 68f459b

Browse files
committed
Minor whitespace / formatting / documentation / dead code tidy-ups.
1 parent 03d8d13 commit 68f459b

File tree

10 files changed

+31
-31
lines changed

10 files changed

+31
-31
lines changed

CHANGELOG.rdoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
== 2.5.0
22

3+
* Added support for new FactoryGirl naming convention.
4+
* Fixed that schema kept prepending additional newlines
5+
* Updates to make annotate smarter about when to touch a model
6+
* Recognize column+type, and don't change a file unless the column+type
7+
combination of the new schema are different than that of the old (i.e., don't
8+
regenerate if columns happen to be in a different order. That's just how life
9+
is sometimes)
310
* Works better with Rails 3
411
* Bugfix: schema kept prepending additional newlines
512
* Updates to make annotate smarter about when to touch a model
@@ -22,6 +29,7 @@
2229
* Leave magic encoding comment intact
2330
* Fix issue #14 - RuntimeError: Already memoized
2431
* Count a model as 'annotated' if any of its tests/fixtures are annotated
32+
* Support FactoryGirl
2533
* Support :change migrations (Rails 3.1)
2634
* Allow models with non-standard capitalization
2735
* Widen type column so we can handle longtexts with chopping things off.

README.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Into Gemfile from Github:
4949

5050
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
5151

52-
Into environment gems From rubygems.org:
52+
Into environment gems from rubygems.org:
5353

5454
gem install annotate
5555

bin/annotate

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ OptionParser.new do |opts|
2222

2323
ENV['position'] = 'before' # hack: make sure default position is "before"
2424
opts.on('-p', '--position [before|after]', ['before', 'after'],
25-
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
25+
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p|
2626
ENV['position'] = p
2727
end
2828

@@ -67,15 +67,15 @@ OptionParser.new do |opts|
6767
end
6868

6969
opts.on('-R', '--require path',
70-
"Additional files to require before loading models") do |path|
71-
if ENV['require']
70+
"Additional file to require before loading models, may be used multiple times") do |path|
71+
if !ENV['require'].blank?
7272
ENV['require'] = ENV['require'] + ",#{path}"
7373
else
7474
ENV['require'] = path
7575
end
76-
end\
76+
end
7777

78-
opts.on('-e', '--exclude [tests,fixtures]', Array, "Do not annotate fixtures, test files, or both") do |exclusions|
78+
opts.on('-e', '--exclude [tests,fixtures,factories]', ['tests','fixtures','factories'], "Do not annotate fixtures, test files, and/or factories") do |exclusions|
7979
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
8080
end
8181

@@ -90,8 +90,6 @@ OptionParser.new do |opts|
9090
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
9191
ENV['trace'] = 'yes'
9292
end
93-
94-
9593
end.parse!
9694

9795
ENV['is_cli'] = '1'

lib/annotate.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ def self.load_tasks
66
if File.exists?('Rakefile')
77
require 'rake'
88
load 'Rakefile'
9-
# Rails 3 wants to load our .rake files for us.
10-
# TODO: selectively do this require on Rails 2.x?
9+
1110
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
1211
return true
1312
else

lib/annotate/active_record_patch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ def self.method_missing(name, *args)
66
# ignore this, so unknown/unloaded macros won't cause parsing to fail
77
end
88
end
9-
end
9+
end

lib/annotate/annotate_models.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ module AnnotateModels
99

1010
# File.join for windows reverse bar compat?
1111
# I dont use windows, can`t test
12-
UNIT_TEST_DIR = File.join("test", "unit" )
12+
UNIT_TEST_DIR = File.join("test", "unit")
1313
SPEC_MODEL_DIR = File.join("spec", "models")
1414
FIXTURE_TEST_DIR = File.join("test", "fixtures")
1515
FIXTURE_SPEC_DIR = File.join("spec", "fixtures")
16-
FIXTURE_DIRS = ["test/fixtures","spec/fixtures"]
1716

1817
# Object Daddy http://github.com/flogic/object_daddy/tree/master
1918
EXEMPLARS_TEST_DIR = File.join("test", "exemplars")
@@ -153,12 +152,9 @@ def get_index_info(klass)
153152
# Returns true or false depending on whether the file was modified.
154153
#
155154
# === Options (opts)
156-
# :position<Symbol>:: where to place the annotated section in fixture or model file,
157-
# :before or :after. Default is :before.
158-
# :position_in_class<Symbol>:: where to place the annotated section in model file
159-
# :position_in_fixture<Symbol>:: where to place the annotated section in fixture file
160-
# :position_in_others<Symbol>:: where to place the annotated section in the rest of
161-
# supported files
155+
# :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
156+
# :position_in_*<Symbol>:: where to place the annotated section in fixture or model file,
157+
# :before or :after. Default is :before.
162158
#
163159
def annotate_one_file(file_name, info_block, options={})
164160
if File.exist?(file_name)
@@ -211,7 +207,9 @@ def annotate_one_file(file_name, info_block, options={})
211207
def remove_annotation_of_file(file_name)
212208
if File.exist?(file_name)
213209
content = File.read(file_name)
210+
214211
content.sub!(PATTERN, '')
212+
215213
File.open(file_name, "wb") { |f| f.puts content }
216214
end
217215
end
@@ -412,7 +410,7 @@ def remove_annotations(options={})
412410
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
413411
end
414412
end
415-
puts "Removed annotation from: #{deannotated.join(', ')}"
413+
puts "Removed annotations from: #{deannotated.join(', ')}"
416414
end
417415

418416
def find_test_file(dir, file_name)

lib/annotate/annotate_routes.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
#
66
#
77
# Prepends the output of "rake routes" to the top of your routes.rb file.
8-
# Yes, it's simple but I'm thick and often need a reminder of what my routes mean.
8+
# Yes, it's simple but I'm thick and often need a reminder of what my routes
9+
# mean.
910
#
10-
# Running this task will replace any exising route comment generated by the task.
11-
# Best to back up your routes file before running:
11+
# Running this task will replace any exising route comment generated by the
12+
# task. Best to back up your routes file before running:
1213
#
1314
# Author:
1415
# Gavin Montague
1516
1617
#
17-
# Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
18+
# Released under the same license as Ruby. No Support. No Warranty.
1819
#
1920
module AnnotateRoutes
2021
PREFIX = "#== Route Map"

lib/generators/annotate_models/install_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def copy_tasks
1111

1212
end
1313
end
14-
end
14+
end

spec/annotate/annotate_models_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def annotate_one_file options = {}
327327
File.read(@model_file_name).should == "#{@schema_info}#{@file_content}"
328328
end
329329

330-
it "should annotate before if given :position => :after" do
330+
it "should annotate after if given :position => :after" do
331331
annotate_one_file :position => :after
332332
File.read(@model_file_name).should == "#{@file_content}\n#{@schema_info}"
333333
end
@@ -373,7 +373,7 @@ class User < ActiveRecord::Base
373373
}.should_not include("/spec/annotate/annotate_models_spec.rb:")
374374
end
375375
end
376-
376+
377377
describe "if a file can't be deannotated" do
378378
before do
379379
write_model('user.rb', <<-EOS)

spec/annotate/annotate_routes_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ def mock_file(stubs={})
99

1010
describe "Annotate Job" do
1111

12-
before(:each) do
13-
File.should_receive(:join).with("config", "routes.rb").and_return("config/routes.rb")
14-
end
15-
1612
it "should check if routes.rb exists" do
1713
File.should_receive(:exists?).with("config/routes.rb").and_return(false)
1814
AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb")

0 commit comments

Comments
 (0)