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.
- data/README.rdoc +11 -3
- data/Rakefile +51 -0
- data/VERSION.yml +2 -1
- data/annotate.gemspec +58 -0
- data/lib/annotate.rb +3 -0
- data/lib/annotate/annotate_models.rb +19 -9
- data/lib/tasks/annotate_models.rake +2 -2
- data/lib/tasks/annotate_routes.rake +1 -1
- data/spec/annotate/annotate_models_spec.rb +10 -1
- data/spec/spec_helper.rb +2 -2
- data/tasks/migrate.rake +1 -1
- data/todo.txt +5 -0
- metadata +49 -37
data/README.rdoc
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/Rakefile
ADDED
@@ -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
|
data/VERSION.yml
CHANGED
data/annotate.gemspec
ADDED
@@ -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
|
+
|
data/lib/annotate.rb
CHANGED
@@ -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(
|
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
|
-
|
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
|
-
#
|
130
|
-
old_content.sub
|
131
|
-
|
132
|
-
|
133
|
-
|
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$/, '')
|
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
|
-
|
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
|
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
|
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,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
2
|
require 'annotate/annotate_models'
|
3
3
|
require 'rubygems'
|
4
|
-
require '
|
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
|
data/spec/spec_helper.rb
CHANGED
data/tasks/migrate.rake
CHANGED
data/todo.txt
ADDED
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.
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
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
|
-
|
46
|
-
homepage: http://github.com/ctran/
|
58
|
+
- todo.txt
|
59
|
+
homepage: http://github.com/ctran/annotate_models
|
47
60
|
licenses: []
|
48
|
-
|
49
61
|
post_install_message:
|
50
|
-
rdoc_options:
|
51
|
-
|
52
|
-
require_paths:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
53
64
|
- lib
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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.
|
79
|
+
rubygems_version: 1.8.10
|
70
80
|
signing_key:
|
71
81
|
specification_version: 3
|
72
|
-
summary: Annotates Rails
|
73
|
-
|
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
|