annotate 2.4.0 → 2.4.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,19 +38,27 @@ Also, if you pass the -r option, it'll annotate routes.rb with the output of "ra
38
38
 
39
39
  == INSTALL
40
40
 
41
- From rubyforge:
41
+ Into Gemfile from Github:
42
+
43
+ gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
44
+
45
+
46
+ Into environment gems From Rubygems.org:
42
47
 
43
48
  sudo gem install annotate
44
49
 
45
- From github:
50
+ Into environment gems from Github checkout:
46
51
 
47
52
  git clone git://github.com/ctran/annotate_models.git annotate
48
53
  cd annotate
49
54
  rake gem
50
55
  sudo gem install pkg/annotate-*.gem
51
56
 
57
+
52
58
  == USAGE
53
59
 
60
+ (If you used the Gemfile install, prefix the below commands with `bundle exec`.)
61
+
54
62
  To annotate all your models, tests, fixtures, etc.:
55
63
 
56
64
  cd /path/to/app
@@ -70,7 +78,7 @@ To annotate routes.rb:
70
78
 
71
79
  To automatically annotate after running 'rake db:migrate':
72
80
 
73
- [needs more clarity] unpack the gem into vendor/plugins, or maybe vendor/gems, or maybe just require tasks/migrate.rake.
81
+ [*needs more clarity*] unpack the gem into vendor/plugins, or maybe vendor/gems, or maybe just require tasks/migrate.rake.
74
82
 
75
83
  If you install annotate_models as a plugin, it will automatically
76
84
  adjust your <tt>rake db:migrate</tt> tasks so that they update the
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ # want other tests/tasks run by default? Add them to the list
5
+ task :default => [:spec]
6
+
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "annotate"
10
+ gem.summary = "Annotates Rails models, routes, fixtures, and others based on the database schema."
11
+ gem.description = "When run, inserts table descriptions from db.schema into a comment block of relevant source code."
12
+ gem.email = ["alex@stinky.com", 'ctran@pragmaquest.com', "x@nofxx.com", "turadg@aleahmad.net"]
13
+ gem.homepage = "http://github.com/ctran/annotate_models"
14
+ gem.authors = ['Cuong Tran', "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad"]
15
+
16
+ gem.rubyforge_project = "annotate"
17
+
18
+ gem.add_development_dependency "rspec"
19
+
20
+ gem.test_files = `git ls-files -- {spec,features}/*`.split("\n")
21
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ gem.require_path = 'lib'
23
+
24
+ # note that Jeweler automatically reads the version from VERSION.yml
25
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
26
+ end
27
+
28
+ Jeweler::GemcutterTasks.new
29
+
30
+
31
+ require "rspec/core/rake_task" # RSpec 2.0
32
+ RSpec::Core::RakeTask.new(:spec) do |t|
33
+ t.pattern = 'spec/*_spec.rb'
34
+ # TODO this leaves out the specs on the library itself
35
+ end
36
+
37
+ # FIXME not working yet
38
+ RSpec::Core::RakeTask.new(:rcov) do |t|
39
+ t.pattern = 'spec/**/*_spec.rb'
40
+ t.rcov = true
41
+ end
42
+
43
+ # FIXME warns "already initialized constant Task"
44
+ # FIXME throws "uninitialized constant RDoc::VISIBILITIES"
45
+ # require 'rdoc/task'
46
+ # RDoc::Task.new do |rdoc|
47
+ # rdoc.main = "README.rdoc"
48
+ # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
49
+ # # require 'lib/annotate'
50
+ # # rdoc.title = "annotate #{Annotate.version}"
51
+ # end
@@ -1,4 +1,5 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 4
4
- :patch: 0
4
+ :patch: 1
5
+ :build: 'beta1'
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "annotate"
8
+ s.version = "2.4.1.beta1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad"]
12
+ s.date = "2011-09-02"
13
+ s.description = "When run, inserts table descriptions from db.schema into a comment block of relevant source code."
14
+ s.email = ["alex@stinky.com", "ctran@pragmaquest.com", "x@nofxx.com", "turadg@aleahmad.net"]
15
+ s.executables = ["annotate"]
16
+ s.extra_rdoc_files = [
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "History.txt",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "annotate.gemspec",
25
+ "bin/annotate",
26
+ "lib/annotate.rb",
27
+ "lib/annotate/annotate_models.rb",
28
+ "lib/annotate/annotate_routes.rb",
29
+ "lib/tasks/annotate_models.rake",
30
+ "lib/tasks/annotate_routes.rake",
31
+ "spec/annotate/annotate_models_spec.rb",
32
+ "spec/annotate/annotate_routes_spec.rb",
33
+ "spec/annotate_spec.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb",
36
+ "tasks/migrate.rake",
37
+ "todo.txt"
38
+ ]
39
+ s.homepage = "http://github.com/ctran/annotate_models"
40
+ s.require_paths = ["lib"]
41
+ s.rubyforge_project = "annotate"
42
+ s.rubygems_version = "1.8.10"
43
+ s.summary = "Annotates Rails models, routes, fixtures, and others based on the database schema."
44
+ s.test_files = ["spec/annotate/annotate_models_spec.rb", "spec/annotate/annotate_routes_spec.rb", "spec/annotate_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 0"])
56
+ end
57
+ end
58
+
@@ -1,6 +1,8 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ require 'yaml'
5
+
4
6
  module Annotate
5
7
  def self.version
6
8
  version_file = File.dirname(__FILE__) + "/../VERSION.yml"
@@ -14,6 +16,7 @@ module Annotate
14
16
 
15
17
  def self.load_tasks
16
18
  if File.exists?('Rakefile')
19
+ require 'rake'
17
20
  load 'Rakefile'
18
21
  Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
19
22
  return true
@@ -119,18 +119,24 @@ module AnnotateModels
119
119
  old_content = File.read(file_name)
120
120
 
121
121
  # Ignore the Schema version line because it changes with each migration
122
- header = Regexp.new(/(^# Table name:.*?\n(#.*\n)*\n)/)
122
+ header = Regexp.new(/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/)
123
123
  old_header = old_content.match(header).to_s
124
124
  new_header = info_block.match(header).to_s
125
125
 
126
- if old_header == new_header
126
+ old_columns = old_header && old_header.scan(/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/).sort
127
+ new_columns = new_header && new_header.scan(/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/).sort
128
+
129
+ if old_columns == new_columns
127
130
  false
128
131
  else
129
- # Remove old schema info
130
- old_content.sub!(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '')
131
-
132
- # Write it back
133
- new_content = options[:position] == 'before' ? (info_block + old_content) : (old_content + "\n" + info_block)
132
+ # Replace the old schema info with the new schema info
133
+ new_content = old_content.sub(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, info_block)
134
+ # But, if there *was* no old schema info, we simply need to insert it
135
+ if new_content == old_content
136
+ new_content = options[:position] == 'before' ?
137
+ (info_block + old_content) :
138
+ ((old_content =~ /\n$/ ? old_content : old_content + '\n') + info_block)
139
+ end
134
140
 
135
141
  File.open(file_name, "wb") { |f| f.puts new_content }
136
142
  true
@@ -228,12 +234,16 @@ module AnnotateModels
228
234
  # in subdirectories without namespacing.
229
235
  def get_model_class(file)
230
236
  require File.expand_path("#{model_dir}/#{file}") # this is for non-rails projects, which don't get Rails auto-require magic
231
- model = file.gsub(/\.rb$/, '').camelize
237
+ model = ActiveSupport::Inflector.camelize(file.gsub(/\.rb$/, ''))
232
238
  parts = model.split('::')
233
239
  begin
234
240
  parts.inject(Object) {|klass, part| klass.const_get(part) }
235
241
  rescue LoadError, NameError
236
- Object.const_get(parts.last)
242
+ begin
243
+ Object.const_get(parts.last)
244
+ rescue LoadError, NameError
245
+ Object.const_get(Module.constants.detect{|c|parts.last.downcase == c.downcase})
246
+ end
237
247
  end
238
248
  end
239
249
 
@@ -1,6 +1,6 @@
1
1
  desc "Add schema information (as comments) to model and fixture files"
2
2
  task :annotate_models => :environment do
3
- require 'annotate/annotate_models'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_models'))
4
4
  options={}
5
5
  options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || :before
6
6
  options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || :before
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  desc "Remove schema information from model and fixture files"
16
16
  task :remove_annotation => :environment do
17
- require 'annotate/annotate_models'
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_models'))
18
18
  options={}
19
19
  options[:model_dir] = ENV['model_dir']
20
20
  AnnotateModels.remove_annotations(options)
@@ -1,5 +1,5 @@
1
1
  desc "Prepends the route map to the top of routes.rb"
2
2
  task :annotate_routes do
3
- require 'annotate/annotate_routes'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_routes'))
4
4
  AnnotateRoutes.do_annotate
5
5
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
  require 'annotate/annotate_models'
3
3
  require 'rubygems'
4
- require 'activesupport'
4
+ require 'active_support'
5
5
 
6
6
  describe AnnotateModels do
7
7
 
@@ -69,6 +69,11 @@ EOS
69
69
  acts_as_awesome :yah
70
70
  end
71
71
  EOS
72
+ create('foo_with_capitals.rb', <<-EOS)
73
+ class FooWithCAPITALS < ActiveRecord::Base
74
+ acts_as_awesome :yah
75
+ end
76
+ EOS
72
77
  end
73
78
  it "should work" do
74
79
  klass = AnnotateModels.get_model_class("foo.rb")
@@ -78,6 +83,10 @@ EOS
78
83
  klass = AnnotateModels.get_model_class("foo_with_macro.rb")
79
84
  klass.name.should == "FooWithMacro"
80
85
  end
86
+ it "should find models with non standard capitalization" do
87
+ klass = AnnotateModels.get_model_class("foo_with_capitals.rb")
88
+ klass.name.should == "FooWithCAPITALS"
89
+ end
81
90
  end
82
91
 
83
92
  end
@@ -2,8 +2,8 @@ begin
2
2
  require 'spec'
3
3
  rescue LoadError
4
4
  require 'rubygems'
5
- gem 'rspec'
6
- require 'spec'
5
+ gem 'rspec-core'
6
+ require 'rspec'
7
7
  end
8
8
 
9
9
  $:.unshift(File.dirname(__FILE__) + '/../lib')
@@ -11,7 +11,7 @@ namespace :db do
11
11
  end
12
12
 
13
13
  namespace :migrate do
14
- [:up, :down, :reset, :redo].each do |t|
14
+ [:change, :up, :down, :reset, :redo].each do |t|
15
15
  task t do
16
16
  Annotate::Migration.update_annotations
17
17
  end
@@ -0,0 +1,5 @@
1
+ TODO
2
+ -----
3
+ change default position back to "top" for all
4
+ add "top" and "bottom" as synonyms for "before" and "after"
5
+ change 'exclude' to 'only' (double negatives are not unconfusing)
metadata CHANGED
@@ -1,35 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: annotate
3
- version: !ruby/object:Gem::Version
4
- version: 2.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.4.1.beta1
5
+ prerelease: 6
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Cuong Tran
8
9
  - Alex Chaffee
9
10
  - Marcos Piccinini
11
+ - Turadg Aleahmad
10
12
  autorequire:
11
13
  bindir: bin
12
14
  cert_chain: []
13
-
14
- date: 2009-12-13 00:00:00 -08:00
15
- default_executable: annotate
16
- dependencies: []
17
-
18
- description: Annotates Rails Models, routes, fixtures, and others based on the database schema.
19
- email:
15
+ date: 2011-09-02 00:00:00.000000000Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rspec
19
+ requirement: &2154511620 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: *2154511620
28
+ description: When run, inserts table descriptions from db.schema into a comment block
29
+ of relevant source code.
30
+ email:
20
31
  - alex@stinky.com
21
32
  - ctran@pragmaquest.com
22
33
  - x@nofxx.com
23
- executables:
34
+ - turadg@aleahmad.net
35
+ executables:
24
36
  - annotate
25
37
  extensions: []
26
-
27
- extra_rdoc_files:
38
+ extra_rdoc_files:
28
39
  - README.rdoc
29
- files:
40
+ files:
30
41
  - History.txt
31
42
  - README.rdoc
43
+ - Rakefile
32
44
  - VERSION.yml
45
+ - annotate.gemspec
33
46
  - bin/annotate
34
47
  - lib/annotate.rb
35
48
  - lib/annotate/annotate_models.rb
@@ -42,36 +55,35 @@ files:
42
55
  - spec/spec.opts
43
56
  - spec/spec_helper.rb
44
57
  - tasks/migrate.rake
45
- has_rdoc: true
46
- homepage: http://github.com/ctran/annotate
58
+ - todo.txt
59
+ homepage: http://github.com/ctran/annotate_models
47
60
  licenses: []
48
-
49
61
  post_install_message:
50
- rdoc_options:
51
- - --charset=UTF-8
52
- require_paths:
62
+ rdoc_options: []
63
+ require_paths:
53
64
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
59
- version:
60
- required_rubygems_version: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: "0"
65
- version:
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>'
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
66
77
  requirements: []
67
-
68
78
  rubyforge_project: annotate
69
- rubygems_version: 1.3.5
79
+ rubygems_version: 1.8.10
70
80
  signing_key:
71
81
  specification_version: 3
72
- summary: Annotates Rails Models, routes, fixtures, and others based on the database schema.
73
- test_files:
82
+ summary: Annotates Rails models, routes, fixtures, and others based on the database
83
+ schema.
84
+ test_files:
74
85
  - spec/annotate/annotate_models_spec.rb
75
86
  - spec/annotate/annotate_routes_spec.rb
76
87
  - spec/annotate_spec.rb
88
+ - spec/spec.opts
77
89
  - spec/spec_helper.rb