Commit 68f459be by Jon Frisby

Minor whitespace / formatting / documentation / dead code tidy-ups.

parent 03d8d138
== 2.5.0 == 2.5.0
* Added support for new FactoryGirl naming convention.
* Fixed that schema kept prepending additional newlines
* Updates to make annotate smarter about when to touch a model
* Recognize column+type, and don't change a file unless the column+type
combination of the new schema are different than that of the old (i.e., don't
regenerate if columns happen to be in a different order. That's just how life
is sometimes)
* Works better with Rails 3 * Works better with Rails 3
* Bugfix: schema kept prepending additional newlines * Bugfix: schema kept prepending additional newlines
* Updates to make annotate smarter about when to touch a model * Updates to make annotate smarter about when to touch a model
...@@ -22,6 +29,7 @@ ...@@ -22,6 +29,7 @@
* Leave magic encoding comment intact * Leave magic encoding comment intact
* Fix issue #14 - RuntimeError: Already memoized * Fix issue #14 - RuntimeError: Already memoized
* Count a model as 'annotated' if any of its tests/fixtures are annotated * Count a model as 'annotated' if any of its tests/fixtures are annotated
* Support FactoryGirl
* Support :change migrations (Rails 3.1) * Support :change migrations (Rails 3.1)
* Allow models with non-standard capitalization * Allow models with non-standard capitalization
* Widen type column so we can handle longtexts with chopping things off. * Widen type column so we can handle longtexts with chopping things off.
......
...@@ -49,7 +49,7 @@ Into Gemfile from Github: ...@@ -49,7 +49,7 @@ Into Gemfile from Github:
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git' gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
Into environment gems From rubygems.org: Into environment gems from rubygems.org:
gem install annotate gem install annotate
......
...@@ -22,7 +22,7 @@ OptionParser.new do |opts| ...@@ -22,7 +22,7 @@ OptionParser.new do |opts|
ENV['position'] = 'before' # hack: make sure default position is "before" ENV['position'] = 'before' # hack: make sure default position is "before"
opts.on('-p', '--position [before|after]', ['before', 'after'], opts.on('-p', '--position [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p| "Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p|
ENV['position'] = p ENV['position'] = p
end end
...@@ -67,15 +67,15 @@ OptionParser.new do |opts| ...@@ -67,15 +67,15 @@ OptionParser.new do |opts|
end end
opts.on('-R', '--require path', opts.on('-R', '--require path',
"Additional files to require before loading models") do |path| "Additional file to require before loading models, may be used multiple times") do |path|
if ENV['require'] if !ENV['require'].blank?
ENV['require'] = ENV['require'] + ",#{path}" ENV['require'] = ENV['require'] + ",#{path}"
else else
ENV['require'] = path ENV['require'] = path
end end
end\ end
opts.on('-e', '--exclude [tests,fixtures]', Array, "Do not annotate fixtures, test files, or both") do |exclusions| opts.on('-e', '--exclude [tests,fixtures,factories]', ['tests','fixtures','factories'], "Do not annotate fixtures, test files, and/or factories") do |exclusions|
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" } exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end end
...@@ -90,8 +90,6 @@ OptionParser.new do |opts| ...@@ -90,8 +90,6 @@ OptionParser.new do |opts|
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value| opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
ENV['trace'] = 'yes' ENV['trace'] = 'yes'
end end
end.parse! end.parse!
ENV['is_cli'] = '1' ENV['is_cli'] = '1'
......
...@@ -6,8 +6,7 @@ module Annotate ...@@ -6,8 +6,7 @@ module Annotate
if File.exists?('Rakefile') if File.exists?('Rakefile')
require 'rake' require 'rake'
load 'Rakefile' load 'Rakefile'
# Rails 3 wants to load our .rake files for us.
# TODO: selectively do this require on Rails 2.x?
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake } Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
return true return true
else else
......
...@@ -9,11 +9,10 @@ module AnnotateModels ...@@ -9,11 +9,10 @@ module AnnotateModels
# File.join for windows reverse bar compat? # File.join for windows reverse bar compat?
# I dont use windows, can`t test # I dont use windows, can`t test
UNIT_TEST_DIR = File.join("test", "unit" ) UNIT_TEST_DIR = File.join("test", "unit")
SPEC_MODEL_DIR = File.join("spec", "models") SPEC_MODEL_DIR = File.join("spec", "models")
FIXTURE_TEST_DIR = File.join("test", "fixtures") FIXTURE_TEST_DIR = File.join("test", "fixtures")
FIXTURE_SPEC_DIR = File.join("spec", "fixtures") FIXTURE_SPEC_DIR = File.join("spec", "fixtures")
FIXTURE_DIRS = ["test/fixtures","spec/fixtures"]
# Object Daddy http://github.com/flogic/object_daddy/tree/master # Object Daddy http://github.com/flogic/object_daddy/tree/master
EXEMPLARS_TEST_DIR = File.join("test", "exemplars") EXEMPLARS_TEST_DIR = File.join("test", "exemplars")
...@@ -153,12 +152,9 @@ module AnnotateModels ...@@ -153,12 +152,9 @@ module AnnotateModels
# Returns true or false depending on whether the file was modified. # Returns true or false depending on whether the file was modified.
# #
# === Options (opts) # === Options (opts)
# :position<Symbol>:: where to place the annotated section in fixture or model file, # :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
# :position_in_*<Symbol>:: where to place the annotated section in fixture or model file,
# :before or :after. Default is :before. # :before or :after. Default is :before.
# :position_in_class<Symbol>:: where to place the annotated section in model file
# :position_in_fixture<Symbol>:: where to place the annotated section in fixture file
# :position_in_others<Symbol>:: where to place the annotated section in the rest of
# supported files
# #
def annotate_one_file(file_name, info_block, options={}) def annotate_one_file(file_name, info_block, options={})
if File.exist?(file_name) if File.exist?(file_name)
...@@ -211,7 +207,9 @@ module AnnotateModels ...@@ -211,7 +207,9 @@ module AnnotateModels
def remove_annotation_of_file(file_name) def remove_annotation_of_file(file_name)
if File.exist?(file_name) if File.exist?(file_name)
content = File.read(file_name) content = File.read(file_name)
content.sub!(PATTERN, '') content.sub!(PATTERN, '')
File.open(file_name, "wb") { |f| f.puts content } File.open(file_name, "wb") { |f| f.puts content }
end end
end end
...@@ -412,7 +410,7 @@ module AnnotateModels ...@@ -412,7 +410,7 @@ module AnnotateModels
puts "\t" + e.backtrace.join("\n\t") if options[:trace] puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end end
end end
puts "Removed annotation from: #{deannotated.join(', ')}" puts "Removed annotations from: #{deannotated.join(', ')}"
end end
def find_test_file(dir, file_name) def find_test_file(dir, file_name)
......
...@@ -5,16 +5,17 @@ ...@@ -5,16 +5,17 @@
# #
# #
# Prepends the output of "rake routes" to the top of your routes.rb file. # Prepends the output of "rake routes" to the top of your routes.rb file.
# Yes, it's simple but I'm thick and often need a reminder of what my routes mean. # Yes, it's simple but I'm thick and often need a reminder of what my routes
# mean.
# #
# Running this task will replace any exising route comment generated by the task. # Running this task will replace any exising route comment generated by the
# Best to back up your routes file before running: # task. Best to back up your routes file before running:
# #
# Author: # Author:
# Gavin Montague # Gavin Montague
# gavin@leftbrained.co.uk # gavin@leftbrained.co.uk
# #
# Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes # Released under the same license as Ruby. No Support. No Warranty.
# #
module AnnotateRoutes module AnnotateRoutes
PREFIX = "#== Route Map" PREFIX = "#== Route Map"
......
...@@ -327,7 +327,7 @@ end ...@@ -327,7 +327,7 @@ end
File.read(@model_file_name).should == "#{@schema_info}#{@file_content}" File.read(@model_file_name).should == "#{@schema_info}#{@file_content}"
end end
it "should annotate before if given :position => :after" do it "should annotate after if given :position => :after" do
annotate_one_file :position => :after annotate_one_file :position => :after
File.read(@model_file_name).should == "#{@file_content}\n#{@schema_info}" File.read(@model_file_name).should == "#{@file_content}\n#{@schema_info}"
end end
......
...@@ -9,10 +9,6 @@ describe AnnotateRoutes do ...@@ -9,10 +9,6 @@ describe AnnotateRoutes do
describe "Annotate Job" do describe "Annotate Job" do
before(:each) do
File.should_receive(:join).with("config", "routes.rb").and_return("config/routes.rb")
end
it "should check if routes.rb exists" do it "should check if routes.rb exists" do
File.should_receive(:exists?).with("config/routes.rb").and_return(false) File.should_receive(:exists?).with("config/routes.rb").and_return(false)
AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb") AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment