Commit 7c5965a5 by Robert Wahler

Merge git://github.com/ctran/annotate_models

* git://github.com/ctran/annotate_models: not continually prepending newlines. 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) Grab old specification even if it has \r\n as line endings rather than pure \ns Remove gemspec line causing a warning Explicitly require rake, fixing rake version compatibility Adding rake as a runtime dependency Correct homepage link to github project Specify development dependencies and ensure correct loading of test libraries Modify the model annontator so that if the schema is already in the model file, it will be replaced into the same location. If it didn't previously exist, it'll be placed according to the "position", as before. Updated require statements in tasks to use full path to lib files. Conflicts: annotate.gemspec lib/annotate/annotate_models.rb
parents ff9d9ded ddfba1f7
......@@ -5,12 +5,12 @@
Gem::Specification.new do |s|
s.name = %q{annotate}
s.version = "2.4.2"
s.version = "2.4.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini"]
s.date = %q{2009-11-16}
s.default_executable = %q{annotate}
s.date = %q{2009-10-23}
#s.default_executable = %q{annotate}
s.description = %q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
s.email = ["alex@stinky.com", "ctran@pragmaquest.com", "x@nofxx.com"]
s.executables = ["annotate"]
......@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
"spec/spec_helper.rb",
"tasks/migrate.rake"
]
s.homepage = %q{http://github.com/ctran/annotate}
s.homepage = %q{http://github.com/ctran/annotate_models}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{annotate}
......@@ -46,6 +46,10 @@ Gem::Specification.new do |s|
"spec/annotate_spec.rb",
"spec/spec_helper.rb"
]
s.add_runtime_dependency('rake')
s.add_development_dependency('jeweler')
s.add_development_dependency('rspec', '~> 1.3.2')
s.add_development_dependency('activesupport', '>= 2.1.0')
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
......
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
require 'yaml'
module Annotate
def self.version
version_file = File.dirname(__FILE__) + "/../VERSION.yml"
......@@ -14,6 +16,7 @@ module Annotate
def self.load_tasks
if File.exists?('Rakefile')
require 'rake'
load 'Rakefile'
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
return true
......
......@@ -128,18 +128,24 @@ module AnnotateModels
old_content = File.read(file_name)
# Ignore the Schema version line because it changes with each migration
header = Regexp.new(/(^# Table name:.*?\n(#.*\n)*\n)/)
header = Regexp.new(/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/)
old_header = old_content.match(header).to_s
new_header = info_block.match(header).to_s
if old_header == new_header
old_columns = old_header && old_header.scan(/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/).sort
new_columns = new_header && new_header.scan(/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/).sort
if old_columns == new_columns
false
else
# Remove old schema info
old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '')
# Write it back
new_content = ((options[:position] || :before).to_sym == :before) ? (info_block + old_content) : (old_content + "\n" + info_block)
# Replace the old schema info with the new schema info
new_content = old_content.sub(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, info_block)
# But, if there *was* no old schema info, we simply need to insert it
if new_content == old_content
new_content = options[:position] == 'before' ?
(info_block + old_content) :
((old_content =~ /\n$/ ? old_content : old_content + '\n') + info_block)
end
File.open(file_name, "wb") { |f| f.puts new_content }
true
......@@ -246,7 +252,7 @@ module AnnotateModels
# in subdirectories without namespacing.
def get_model_class(file)
require File.expand_path("#{model_dir}/#{file}") # this is for non-rails projects, which don't get Rails auto-require magic
model = file.gsub(/\.rb$/, '').camelize
model = ActiveSupport::Inflector.camelize(file.gsub(/\.rb$/, ''))
parts = model.split('::')
begin
parts.inject(Object) {|klass, part| klass.const_get(part) }
......
desc "Add schema information (as comments) to model and fixture files"
task :annotate_models => :environment do
require 'annotate/annotate_models'
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_models'))
options={}
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || :before
options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || :before
......@@ -15,7 +15,7 @@ end
desc "Remove schema information from model and fixture files"
task :remove_annotation => :environment do
require 'annotate/annotate_models'
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_models'))
options={}
options[:model_dir] = ENV['model_dir']
AnnotateModels.remove_annotations(options)
......
desc "Prepends the route map to the top of routes.rb"
task :annotate_routes do
require 'annotate/annotate_routes'
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_routes'))
AnnotateRoutes.do_annotate
end
require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_models'
require 'rubygems'
require 'activesupport'
require 'active_support'
describe AnnotateModels 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