Commit 9e3b6385 by Marcos Piccinini

merge ctran new stuff

parents 3d1d6a1c 8ecd23ee
== 1.0.2 2008-03-22 == 2.0 2009-02-03
* Add contributions from Michael Bumann (http://github.com/bumi)
* added an option "position" to choose to put the annotation,
* spec/fixtures now also get annotated
* added a task to remove the annotations
* these options can be specified from command line as -d and -p [before|after]
== 1.0.3 2008-05-02
* Add misc changes from Dustin Sallings and Henrik N
* Remove trailing whitespace
* More intuitive info messages
* Update README file with update-to-date example
== 2.0.0 2008-12-25
* Add annotate_models plugin fork additions * Add annotate_models plugin fork additions
* Annotates Rspec and Test Unit models * Annotates Rspec and Test Unit models
...@@ -22,6 +7,21 @@ ...@@ -22,6 +7,21 @@
* Add AnnotateRoutes rake task * Add AnnotateRoutes rake task
* Up gem structure to newgem defaults * Up gem structure to newgem defaults
== 1.0.4 2008-09-04
* Only update modified models since last run, thanks to sant0sk1
== 1.0.3 2008-05-02
* Add misc changes from Dustin Sallings and Henrik N
* Remove trailing whitespace
* More intuitive info messages
* Update README file with update-to-date example
== 1.0.2 2008-03-22
* Add contributions from Michael Bumann (http://github.com/bumi)
* added an option "position" to choose to put the annotation,
* spec/fixtures now also get annotated
* added a task to remove the annotations
* these options can be specified from command line as -d and -p [before|after]
The MIT License
Copyright (c) 2008 Dave Thomas
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
History.txt
License.txt
Manifest.txt
README.rdoc
Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
tasks/rspec.rake
History.txt
License.txt
Manifest.txt
README.rdoc
Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
tasks/rspec.rake
History.txt
License.txt
Manifest.txt
README.rdoc
Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
tasks/rspec.rake
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
Add a comment summarizing the current schema to the bottom of each Add a comment summarizing the current schema to the bottom of each
ActiveRecord model, test file and fixture. ActiveRecord model, fixture file.
If you are using Object Daddy, it`ll annotate your example files too. If you are using Object Daddy, it`ll annotate your example files too.
# == Schema Info # == Schema Info
# Schema version: 20081001061831
# #
# Table name: line_item # Table name: line_items
# #
# id :integer(11) not null, primary key # id :integer(11) not null, primary key
# quantity :integer(11) not null # quantity :integer(11) not null
...@@ -27,7 +27,6 @@ If you are using Object Daddy, it`ll annotate your example files too. ...@@ -27,7 +27,6 @@ If you are using Object Daddy, it`ll annotate your example files too.
Annotates geometrical columns, geom type and srid, when using SpatialAdapter or PostgisAdapter: Annotates geometrical columns, geom type and srid, when using SpatialAdapter or PostgisAdapter:
# == Schema Info # == Schema Info
# Schema version: 20081213204851
# #
# Table name: trips # Table name: trips
# #
...@@ -41,6 +40,28 @@ Annotates geometrical columns, geom type and srid, when using SpatialAdapter or ...@@ -41,6 +40,28 @@ Annotates geometrical columns, geom type and srid, when using SpatialAdapter or
== HOW TO USE: == HOW TO USE:
=======
== Warning
Note that this code will blow away the initial/final comment
block in your models if it looks like it was previously added
by annotate models, so you don't want to add additional text
to an automatically created comment block.
* * Back up your model files before using... * *
== Install
From rubyforge:
sudo gem install annotate
From github:
gem sources -a http://gems.github.com
sudo gem install ctran-annotate
== Usage
To annotate all your models: To annotate all your models:
...@@ -51,7 +72,6 @@ To annotate routes.rb: ...@@ -51,7 +72,6 @@ To annotate routes.rb:
annotate -r annotate -r
More: More:
annotate -h annotate -h
...@@ -91,14 +111,27 @@ to an automatically created comment block. ...@@ -91,14 +111,27 @@ to an automatically created comment block.
== LICENSE: == LICENSE:
=======
More options:
Usage: annotate [options]
-d, --delete Remove annotations from all model files
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model file
-r, --routes Annotate routes.rb with the output of 'rake routes'
-v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation
-i, --show-indexes List the table's database indexes in the annotation
--model-dir dir Annotate model files stored in dir rather than app/models
Original code by: == LICENSE:
Dave Thomas -- Pragmatic Programmers, LLC Released under the same license as Ruby. No Support. No Warranty.
Refactored, improved and maintained by: == Author:
Marcos Piccinini ( http://github.com/nofxx/annotate ) Original code by:
Dave Thomas -- Pragmatic Programmers, LLC
AnnotateModels mods by: AnnotateModels mods by:
...@@ -116,10 +149,18 @@ AnnotateRoutes originally by: ...@@ -116,10 +149,18 @@ AnnotateRoutes originally by:
== Modifications == Modifications
- alex@pivotallabs.com - alex@pivotallabs.com
=======
Modifications by:
- Alex Chaffee - http://github.com/alexch - alex@pivotallabs.com
- Cuong Tran - http://github.com/ctran - Cuong Tran - http://github.com/ctran
- Jack Danger - http://github.com/JackDanger - Jack Danger - http://github.com/JackDanger
- Michael Bumann - http://github.com/bumi - Michael Bumann - http://github.com/bumi
- Henrik Nyh - http://github.com/henrik - Henrik Nyh - http://github.com/henrik
- Marcos Piccinini - http://github.com/nofxx
and many others that I may have missed to add.
Released under the same license as Ruby. No Support. No Warranty. == This fork
Marcos Piccinini ( http://github.com/nofxx/annotate )
\ No newline at end of file
...@@ -4,12 +4,12 @@ require File.dirname(__FILE__) + '/lib/annotate' ...@@ -4,12 +4,12 @@ require File.dirname(__FILE__) + '/lib/annotate'
# Generate all the Rake tasks # Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory) # Run 'rake -T' to see list of generated tasks (from gem root directory)
$hoe = Hoe.new('annotate', Annotate::VERSION) do |p| $hoe = Hoe.new('annotate', Annotate::VERSION) do |p|
p.developer('Marcos Piccinini', 'x@nofxx.com') p.developer('Cuong Tran', 'ctran@pragmaquest.com')
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n") p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
p.rubyforge_name = p.name p.rubyforge_name = 'annotate-models'
p.url = "http://github.com/nofxx/annotate" p.url = "http://github.com/ctran/annotate_models"
p.summary = "Annotates Rails Models and Routes" p.summary = "Annotates Rails Models, routes, and others"
p.description = "Annotates Rails Models and Routes" p.description = "Annotates Rails Models, routes, and others"
p.extra_dev_deps = [ p.extra_dev_deps = [
['newgem', ">= #{::Newgem::VERSION}"] ['newgem', ">= #{::Newgem::VERSION}"]
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{annotate} s.name = %q{annotate}
<<<<<<< HEAD:annotate.gemspec
s.version = "2.2.7" s.version = "2.2.7"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
...@@ -20,12 +21,33 @@ Gem::Specification.new do |s| ...@@ -20,12 +21,33 @@ Gem::Specification.new do |s|
s.rubyforge_project = %q{annotate} s.rubyforge_project = %q{annotate}
s.rubygems_version = %q{1.3.1} s.rubygems_version = %q{1.3.1}
s.summary = %q{Annotates Rails Models and Routes} s.summary = %q{Annotates Rails Models and Routes}
=======
s.version = "2.0.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran"]
s.date = %q{2009-05-06}
s.default_executable = %q{annotate}
s.description = %q{Annotates Rails Models, routes, and others}
s.email = ["ctran@pragmaquest.com"]
s.executables = ["annotate"]
s.extra_rdoc_files = ["History.txt", "README.rdoc"]
s.files = ["History.txt", "README.rdoc", "Rakefile", "annotate_models.gemspec", "bin/annotate", "lib/annotate.rb", "lib/annotate/annotate_models.rb", "lib/annotate/annotate_routes.rb", "lib/tasks/annotate_models.rake", "lib/tasks/annotate_routes.rake"]
s.has_rdoc = true
s.homepage = %q{http://github.com/ctran/annotate_models}
s.rdoc_options = ["--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{annotate-models}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Annotates Rails Models, routes, and others}
>>>>>>> ctran/master:annotate.gemspec
if s.respond_to? :specification_version then if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2 s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
<<<<<<< HEAD:annotate.gemspec
s.add_development_dependency(%q<newgem>, [">= 1.3.0"]) s.add_development_dependency(%q<newgem>, [">= 1.3.0"])
s.add_development_dependency(%q<hoe>, [">= 1.8.0"]) s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
else else
...@@ -34,6 +56,16 @@ Gem::Specification.new do |s| ...@@ -34,6 +56,16 @@ Gem::Specification.new do |s|
end end
else else
s.add_dependency(%q<newgem>, [">= 1.3.0"]) s.add_dependency(%q<newgem>, [">= 1.3.0"])
=======
s.add_development_dependency(%q<newgem>, [">= 1.4.1"])
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
else
s.add_dependency(%q<newgem>, [">= 1.4.1"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
else
s.add_dependency(%q<newgem>, [">= 1.4.1"])
>>>>>>> ctran/master:annotate.gemspec
s.add_dependency(%q<hoe>, [">= 1.8.0"]) s.add_dependency(%q<hoe>, [">= 1.8.0"])
end end
end end
./annotate.gemspec
\ No newline at end of file
...@@ -7,15 +7,17 @@ task = :annotate_models ...@@ -7,15 +7,17 @@ task = :annotate_models
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: annotate [options]" opts.banner = "Usage: annotate [options]"
opts.on('-d', '--delete') { task = :remove_annotation } opts.on('-d', '--delete', "Remove annotations from all model files") { task = :remove_annotation }
opts.on('-p', '--position [before|after]', ['before', 'after']) { |p| ENV['position'] = p } opts.on('-p', '--position [before|after]', ['before', 'after'], "Place the annotations at the top (before) or the bottom (after) of the model file") { |p| ENV['position'] = p }
opts.on('-r', '--routes') { task = :annotate_routes } opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") { task = :annotate_routes }
opts.on('-v', '--version') { puts "Annotate v#{Annotate::VERSION}"; exit } opts.on('-v', '--version', "Show the current version of this gem") { puts "Annotate v#{Annotate::VERSION}"; exit }
opts.on('-m', '--show-migration', "Include the migration version number in the annotation") { ENV['include_version'] = "yes" }
opts.on('-i', '--show-indexes', "List the table's database indexes in the annotation") { ENV['show_indexes'] = "yes" }
opts.on('--model-dir dir', "Annotate model files stored in dir rather than app/models") {|dir| ENV['model_dir'] = dir }
end.parse! end.parse!
begin if Annotate.load_tasks
Rake::Task[task].invoke Rake::Task[task].invoke
#TODO: rescue only rake error else
rescue NameError => e STDERR.puts "Can't find Rakefile. Are we in a Rails folder?"
puts "Can`t find Rake. Are we in a Rails folder?"
end end
...@@ -2,13 +2,15 @@ $:.unshift(File.dirname(__FILE__)) unless ...@@ -2,13 +2,15 @@ $:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module Annotate module Annotate
VERSION = '2.2.7' VERSION = '2.3'
end
begin def self.load_tasks
if File.exists?('Rakefile')
load 'Rakefile' load 'Rakefile'
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake } Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
rescue LoadError => e return true
nil else
return false
end
end
end end
...@@ -3,8 +3,6 @@ module AnnotateModels ...@@ -3,8 +3,6 @@ module AnnotateModels
# Annotate Models plugin use this header # Annotate Models plugin use this header
COMPAT_PREFIX = "== Schema Info" COMPAT_PREFIX = "== Schema Info"
PREFIX = "== Schema Information" PREFIX = "== Schema Information"
MODEL_DIR = "app/models"
FIXTURE_DIRS = ["test/fixtures","spec/fixtures"] FIXTURE_DIRS = ["test/fixtures","spec/fixtures"]
# 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
...@@ -13,6 +11,13 @@ module AnnotateModels ...@@ -13,6 +11,13 @@ module AnnotateModels
# Object Daddy http://github.com/flogic/object_daddy/tree/master # Object Daddy http://github.com/flogic/object_daddy/tree/master
EXEMPLARS_DIR = File.join("spec", "exemplars") EXEMPLARS_DIR = File.join("spec", "exemplars")
def model_dir
@model_dir || "app/models"
end
def model_dir=(dir)
@model_dir = dir
end
# Simple quoting for the default column value # Simple quoting for the default column value
def quote(value) def quote(value)
...@@ -32,7 +37,7 @@ module AnnotateModels ...@@ -32,7 +37,7 @@ module AnnotateModels
# to create a comment block containing a line for # to create a comment block containing a line for
# each column. The line contains the column name, # each column. The line contains the column name,
# the type (and length), and any optional attributes # the type (and length), and any optional attributes
def get_schema_info(klass, header) def get_schema_info(klass, header, options = {})
info = "# #{header}\n#\n" info = "# #{header}\n#\n"
info << "# Table name: #{klass.table_name}\n#\n" info << "# Table name: #{klass.table_name}\n#\n"
...@@ -59,9 +64,26 @@ module AnnotateModels ...@@ -59,9 +64,26 @@ module AnnotateModels
info << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n" info << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
end end
if options[:show_indexes]
info << get_index_info(klass)
end
info << "#\n\n" info << "#\n\n"
end end
def get_index_info(klass)
index_info = "#\n# Indexes\n#\n"
indexes = klass.connection.indexes(klass.table_name)
return "" if indexes.empty?
max_size = indexes.collect{|index| index.name.size}.max + 1
indexes.each do |index|
index_info << sprintf("# %-#{max_size}.#{max_size}s %s %s", index.name, "(#{index.columns.join(",")})", index.unique ? "UNIQUE" : "").rstrip + "\n"
end
return index_info
end
# Add a schema block to a file. If the file already contains # Add a schema block to a file. If the file already contains
# a schema info block (a comment starting with "== Schema Information"), check if it # a schema info block (a comment starting with "== Schema Information"), check if it
# matches the block that is already there. If so, leave it be. If not, remove the old # matches the block that is already there. If so, leave it be. If not, remove the old
...@@ -92,7 +114,7 @@ module AnnotateModels ...@@ -92,7 +114,7 @@ module AnnotateModels
old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '') old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '')
# Write it back # Write it back
new_content = options[:position] == "before" ? (info_block + old_content) : (old_content + "\n" + info_block) new_content = ((options[:position] || :before).to_sym == :before) ? (info_block + old_content) : (old_content + "\n" + info_block)
File.open(file_name, "wb") { |f| f.puts new_content } File.open(file_name, "wb") { |f| f.puts new_content }
true true
...@@ -118,10 +140,10 @@ module AnnotateModels ...@@ -118,10 +140,10 @@ module AnnotateModels
# files were modified. # files were modified.
def annotate(klass, file, header,options={}) def annotate(klass, file, header,options={})
info = get_schema_info(klass, header) info = get_schema_info(klass, header, options)
annotated = false annotated = false
model_name = klass.name.underscore model_name = klass.name.underscore
model_file_name = File.join(MODEL_DIR, file) model_file_name = File.join(model_dir, file)
if annotate_one_file(model_file_name, info, options.merge( if annotate_one_file(model_file_name, info, options.merge(
:position=>(options[:position_in_class] || options[:position]))) :position=>(options[:position_in_class] || options[:position])))
annotated = true annotated = true
...@@ -131,7 +153,7 @@ module AnnotateModels ...@@ -131,7 +153,7 @@ module AnnotateModels
File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"), # test File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"), # test
File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"), # spec File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"), # spec
File.join(EXEMPLARS_DIR, "#{model_name}_exemplar.rb"), # Object Daddy File.join(EXEMPLARS_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
].each { |file| annotate_one_file(file, info, options.merge(:position=>(options[:position_in_others] || options[:position]))) } ].each { |file| annotate_one_file(file, info) }
FIXTURE_DIRS.each do |dir| FIXTURE_DIRS.each do |dir|
fixture_file_name = File.join(dir,klass.table_name + ".yml") fixture_file_name = File.join(dir,klass.table_name + ".yml")
...@@ -144,13 +166,13 @@ module AnnotateModels ...@@ -144,13 +166,13 @@ module AnnotateModels
# command line arguments, they're assumed to be either # command line arguments, they're assumed to be either
# the underscore or CamelCase versions of model names. # the underscore or CamelCase versions of model names.
# Otherwise we take all the model files in the # Otherwise we take all the model files in the
# app/models directory. # model_dir directory.
def get_model_files def get_model_files
models = ARGV.dup models = ARGV.dup
models.shift models.shift
models.reject!{|m| m.starts_with?("position=")} models.reject!{|m| m.starts_with?("position=")}
if models.empty? if models.empty?
Dir.chdir(MODEL_DIR) do Dir.chdir(model_dir) do
models = Dir["**/*.rb"] models = Dir["**/*.rb"]
end end
end end
...@@ -161,6 +183,7 @@ module AnnotateModels ...@@ -161,6 +183,7 @@ module AnnotateModels
# Check for namespaced models in subdirectories as well as models # Check for namespaced models in subdirectories as well as models
# in subdirectories without namespacing. # in subdirectories without namespacing.
def get_model_class(file) def get_model_class(file)
require "#{model_dir}/#{file}" # this is for non-rails projects, which don't get Rails auto-require magic
model = file.gsub(/\.rb$/, '').camelize model = file.gsub(/\.rb$/, '').camelize
parts = model.split('::') parts = model.split('::')
begin begin
...@@ -176,10 +199,17 @@ module AnnotateModels ...@@ -176,10 +199,17 @@ module AnnotateModels
# then pas it to the associated block # then pas it to the associated block
def do_annotations(options={}) def do_annotations(options={})
header = PREFIX.dup header = PREFIX.dup
if options[:include_version]
version = ActiveRecord::Migrator.current_version rescue 0 version = ActiveRecord::Migrator.current_version rescue 0
if version > 0 if version > 0
header << "\n# Schema version: #{version}" header << "\n# Schema version: #{version}"
end end
end
if options[:model_dir]
self.model_dir = options[:model_dir]
end
annotated = [] annotated = []
get_model_files.each do |file| get_model_files.each do |file|
...@@ -191,7 +221,7 @@ module AnnotateModels ...@@ -191,7 +221,7 @@ module AnnotateModels
end end
end end
rescue Exception => e rescue Exception => e
puts "Unable to annotate #{file}: #{e.message}" puts "Unable to annotate #{file}: #{e.message} (#{e.backtrace.first})"
end end
end end
if annotated.empty? if annotated.empty?
...@@ -201,7 +231,12 @@ module AnnotateModels ...@@ -201,7 +231,12 @@ module AnnotateModels
end end
end end
def remove_annotations def remove_annotations(options={})
p options
if options[:model_dir]
puts "removing"
self.model_dir = options[:model_dir]
end
deannotated = [] deannotated = []
get_model_files.each do |file| get_model_files.each do |file|
begin begin
...@@ -209,7 +244,7 @@ module AnnotateModels ...@@ -209,7 +244,7 @@ module AnnotateModels
if klass < ActiveRecord::Base && !klass.abstract_class? if klass < ActiveRecord::Base && !klass.abstract_class?
deannotated << klass deannotated << klass
model_file_name = File.join(MODEL_DIR, file) model_file_name = File.join(model_dir, file)
remove_annotation_of_file(model_file_name) remove_annotation_of_file(model_file_name)
FIXTURE_DIRS.each do |dir| FIXTURE_DIRS.each do |dir|
......
...@@ -2,14 +2,18 @@ desc "Add schema information (as comments) to model and fixture files" ...@@ -2,14 +2,18 @@ desc "Add schema information (as comments) to model and fixture files"
task :annotate_models => :environment do task :annotate_models => :environment do
require 'annotate/annotate_models' require 'annotate/annotate_models'
options={} options={}
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || :before
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || :before
options[:position_in_others] = ENV['position_in_others'] || ENV['position'] options[:show_indexes] = ENV['show_indexes']
options[:model_dir] = ENV['model_dir']
options[:include_version] = ENV['include_version']
AnnotateModels.do_annotations(options) AnnotateModels.do_annotations(options)
end end
desc "Remove schema information from model and fixture files" desc "Remove schema information from model and fixture files"
task :remove_annotation => :environment do task :remove_annotation => :environment do
require 'annotate_models' require 'annotate/annotate_models'
AnnotateModels.remove_annotations options={}
options[:model_dir] = ENV['model_dir']
AnnotateModels.remove_annotations(options)
end end
...@@ -5,6 +5,11 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' ...@@ -5,6 +5,11 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
libs = " -r irb/completion" libs = " -r irb/completion"
# Perhaps use a console_lib to store any extra methods I may want available in the cosole # Perhaps use a console_lib to store any extra methods I may want available in the cosole
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}" # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
<<<<<<< HEAD:script/console
libs << " -r #{File.dirname(__FILE__) + '/../lib/annotate.rb'}" libs << " -r #{File.dirname(__FILE__) + '/../lib/annotate.rb'}"
puts "Loading annotate gem" puts "Loading annotate gem"
=======
libs << " -r #{File.dirname(__FILE__) + '/../lib/annotate_models.rb'}"
puts "Loading annotate_models gem"
>>>>>>> ctran/master:script/console
exec "#{irb} #{libs} --simple-prompt" exec "#{irb} #{libs} --simple-prompt"
\ No newline at end of file
...@@ -27,8 +27,16 @@ describe AnnotateModels do ...@@ -27,8 +27,16 @@ describe AnnotateModels do
:columns => [ :columns => [
mock_column(:type => "integer", :default => nil, :null => false, :name => "id", :limit => nil), mock_column(:type => "integer", :default => nil, :null => false, :name => "id", :limit => nil),
mock_column(:type => "string", :default => nil, :null => false, :name => "name", :limit => 50) mock_column(:type => "string", :default => nil, :null => false, :name => "name", :limit => 50)
]), "Hello").should eql("# Hello\n#\n# Table name: users\n#\n# id :integer not null, primary key\n# id :integer not null, primary key\n#\n\n") ]), "Schema Info").should eql(<<-EOS)
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key
# id :integer not null, primary key
#
EOS
end end
......
...@@ -25,7 +25,7 @@ describe AnnotateRoutes do ...@@ -25,7 +25,7 @@ describe AnnotateRoutes do
File.should_receive(:exists?).with("config/routes.rb").and_return(true) File.should_receive(:exists?).with("config/routes.rb").and_return(true)
AnnotateRoutes.should_receive(:`).with("rake routes").and_return("bad line\ngood line") AnnotateRoutes.should_receive(:`).with("rake routes").and_return("bad line\ngood line")
File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file) File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
AnnotateRoutes.should_receive(:puts).with("Route map annotated.") AnnotateRoutes.should_receive(:puts).with("Route file annotated.")
end end
it "should annotate and add a newline!" do it "should annotate and add a newline!" do
......
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