nofxx-annotate 2.3.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -0
- data/annotate.gemspec +7 -4
- data/bin/annotate +40 -7
- data/lib/annotate/annotate_models.rb +38 -9
- data/lib/tasks/annotate_models.rake +2 -0
- data/spec/annotate/annotate_models_spec.rb +40 -0
- metadata +5 -4
- data/VERSION.yml +0 -4
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.2
|
data/annotate.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{annotate}
|
5
|
-
s.version = "2.3.
|
8
|
+
s.version = "2.3.2"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Cuong Tran", "Marcos Piccinini"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-08-21}
|
10
13
|
s.default_executable = %q{annotate}
|
11
14
|
s.email = %q{x@nofxx.com}
|
12
15
|
s.executables = ["annotate"]
|
@@ -18,7 +21,7 @@ Gem::Specification.new do |s|
|
|
18
21
|
"History.txt",
|
19
22
|
"README.rdoc",
|
20
23
|
"Rakefile",
|
21
|
-
"VERSION
|
24
|
+
"VERSION",
|
22
25
|
"annotate.gemspec",
|
23
26
|
"bin/annotate",
|
24
27
|
"lib/annotate.rb",
|
@@ -35,7 +38,7 @@ Gem::Specification.new do |s|
|
|
35
38
|
s.homepage = %q{http://github.com/nofxx/annotate}
|
36
39
|
s.rdoc_options = ["--charset=UTF-8"]
|
37
40
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.
|
41
|
+
s.rubygems_version = %q{1.3.5}
|
39
42
|
s.summary = %q{Annotates Rails Models, routes, and others}
|
40
43
|
s.test_files = [
|
41
44
|
"spec/annotate/annotate_models_spec.rb",
|
data/bin/annotate
CHANGED
@@ -7,13 +7,46 @@ task = :annotate_models
|
|
7
7
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: annotate [options]"
|
10
|
-
opts.on('-d', '--delete',
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
opts.on('-
|
15
|
-
|
16
|
-
|
10
|
+
opts.on('-d', '--delete',
|
11
|
+
"Remove annotations from all model files") do
|
12
|
+
task = :remove_annotation
|
13
|
+
end
|
14
|
+
opts.on('-p', '--position [before|after]', ['before', 'after'],
|
15
|
+
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
|
16
|
+
ENV['position'] = p
|
17
|
+
end
|
18
|
+
opts.on('-r', '--routes',
|
19
|
+
"Annotate routes.rb with the output of 'rake routes'") do
|
20
|
+
task = :annotate_routes
|
21
|
+
end
|
22
|
+
opts.on('-v', '--version',
|
23
|
+
"Show the current version of this gem") do
|
24
|
+
puts "Annotate v#{Annotate::VERSION}"; exit
|
25
|
+
end
|
26
|
+
opts.on('-m', '--show-migration',
|
27
|
+
"Include the migration version number in the annotation") do
|
28
|
+
ENV['include_version'] = "yes"
|
29
|
+
end
|
30
|
+
opts.on('-i', '--show-indexes',
|
31
|
+
"List the table's database indexes in the annotation") do
|
32
|
+
ENV['show_indexes'] = "yes"
|
33
|
+
end
|
34
|
+
opts.on('-s', '--simple-indexes',
|
35
|
+
"Concat the column's related indexes in the annotation") do
|
36
|
+
ENV['simple_indexes'] = "yes"
|
37
|
+
end
|
38
|
+
opts.on('--model-dir dir',
|
39
|
+
"Annotate model files stored in dir rather than app/models") do |dir|
|
40
|
+
ENV['model_dir'] = dir
|
41
|
+
end
|
42
|
+
opts.on('-R', '--require path',
|
43
|
+
"Additional files to require before loading models") do |path|
|
44
|
+
if ENV['require']
|
45
|
+
ENV['require'] = ENV['require'] + ",#{path}"
|
46
|
+
else
|
47
|
+
ENV['require'] = path
|
48
|
+
end
|
49
|
+
end
|
17
50
|
end.parse!
|
18
51
|
|
19
52
|
if Annotate.load_tasks
|
@@ -8,10 +8,11 @@ module AnnotateModels
|
|
8
8
|
# I dont use windows, can`t test
|
9
9
|
UNIT_TEST_DIR = File.join("test", "unit" )
|
10
10
|
SPEC_MODEL_DIR = File.join("spec", "models")
|
11
|
+
EXEMPLARS_TEST_DIR = File.join("test", "exemplars")
|
11
12
|
# Object Daddy http://github.com/flogic/object_daddy/tree/master
|
12
|
-
|
13
|
+
EXEMPLARS_SPEC_DIR = File.join("spec", "exemplars")
|
13
14
|
# Machinist http://github.com/notahat/machinist
|
14
|
-
|
15
|
+
BLUEPRINTS_DIR = File.join("test", "blueprints")
|
15
16
|
|
16
17
|
def model_dir
|
17
18
|
@model_dir || "app/models"
|
@@ -63,6 +64,17 @@ module AnnotateModels
|
|
63
64
|
attrs << "#{col.geometry_type}, #{col.srid}"
|
64
65
|
end
|
65
66
|
|
67
|
+
# Check if the column has indices and print "indexed" if true
|
68
|
+
# If the indice include another colum, print it too.
|
69
|
+
if options[:simple_indexes] # Check out if this column is indexed
|
70
|
+
indices = klass.connection.indexes(klass.table_name)
|
71
|
+
if indices = indices.select { |ind| ind.columns.include? col.name }
|
72
|
+
indices.each do |ind|
|
73
|
+
ind = ind.columns.reject! { |i| i == col.name }
|
74
|
+
attrs << (ind.length == 0 ? "indexed" : "indexed => [#{ind.join(", ")}]")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
66
78
|
info << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
|
67
79
|
end
|
68
80
|
|
@@ -152,9 +164,11 @@ module AnnotateModels
|
|
152
164
|
end
|
153
165
|
|
154
166
|
[
|
155
|
-
File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"),
|
156
|
-
File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"),
|
157
|
-
File.join(
|
167
|
+
File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"), # test
|
168
|
+
File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"), # spec
|
169
|
+
File.join(EXEMPLARS_TEST_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
|
170
|
+
File.join(EXEMPLARS_SPEC_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
|
171
|
+
File.join(BLUEPRINTS_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
|
158
172
|
].each { |file| annotate_one_file(file, info) }
|
159
173
|
|
160
174
|
FIXTURE_DIRS.each do |dir|
|
@@ -185,7 +199,7 @@ module AnnotateModels
|
|
185
199
|
# Check for namespaced models in subdirectories as well as models
|
186
200
|
# in subdirectories without namespacing.
|
187
201
|
def get_model_class(file)
|
188
|
-
require "#{model_dir}/#{file}" # this is for non-rails projects, which don't get Rails auto-require magic
|
202
|
+
require File.expand_path("#{model_dir}/#{file}") # this is for non-rails projects, which don't get Rails auto-require magic
|
189
203
|
model = file.gsub(/\.rb$/, '').camelize
|
190
204
|
parts = model.split('::')
|
191
205
|
begin
|
@@ -198,8 +212,14 @@ module AnnotateModels
|
|
198
212
|
# We're passed a name of things that might be
|
199
213
|
# ActiveRecord models. If we can find the class, and
|
200
214
|
# if its a subclass of ActiveRecord::Base,
|
201
|
-
# then
|
215
|
+
# then pass it to the associated block
|
202
216
|
def do_annotations(options={})
|
217
|
+
if options[:require]
|
218
|
+
options[:require].each do |path|
|
219
|
+
require path
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
203
223
|
header = PREFIX.dup
|
204
224
|
|
205
225
|
if options[:include_version]
|
@@ -227,14 +247,13 @@ module AnnotateModels
|
|
227
247
|
end
|
228
248
|
end
|
229
249
|
if annotated.empty?
|
230
|
-
puts "Nothing annotated
|
250
|
+
puts "Nothing annotated."
|
231
251
|
else
|
232
252
|
puts "Annotated (#{annotated.length}): #{annotated.join(', ')}"
|
233
253
|
end
|
234
254
|
end
|
235
255
|
|
236
256
|
def remove_annotations(options={})
|
237
|
-
p options
|
238
257
|
if options[:model_dir]
|
239
258
|
puts "removing"
|
240
259
|
self.model_dir = options[:model_dir]
|
@@ -262,3 +281,13 @@ module AnnotateModels
|
|
262
281
|
end
|
263
282
|
end
|
264
283
|
end
|
284
|
+
|
285
|
+
# monkey patches
|
286
|
+
|
287
|
+
module ::ActiveRecord
|
288
|
+
class Base
|
289
|
+
def self.method_missing(name, *args)
|
290
|
+
# ignore this, so unknown/unloaded macros won't cause parsing to fail
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
@@ -5,8 +5,10 @@ task :annotate_models => :environment do
|
|
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
|
7
7
|
options[:show_indexes] = ENV['show_indexes']
|
8
|
+
options[:simple_indexes] = ENV['simple_indexes']
|
8
9
|
options[:model_dir] = ENV['model_dir']
|
9
10
|
options[:include_version] = ENV['include_version']
|
11
|
+
options[:require] = ENV['require'].split(',') rescue []
|
10
12
|
AnnotateModels.do_annotations(options)
|
11
13
|
end
|
12
14
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
2
|
require 'annotate/annotate_models'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'activesupport'
|
3
5
|
|
4
6
|
describe AnnotateModels do
|
5
7
|
|
@@ -21,6 +23,7 @@ describe AnnotateModels do
|
|
21
23
|
it "should get schema info" do
|
22
24
|
|
23
25
|
AnnotateModels.get_schema_info(mock_klass(
|
26
|
+
:connection => mock("Conn", :indexes => []),
|
24
27
|
:table_name => "users",
|
25
28
|
:primary_key => "id",
|
26
29
|
:column_names => ["id","login"],
|
@@ -40,4 +43,41 @@ EOS
|
|
40
43
|
|
41
44
|
end
|
42
45
|
|
46
|
+
describe "#get_model_class" do
|
47
|
+
module ::ActiveRecord
|
48
|
+
class Base
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def create(file, body="hi")
|
53
|
+
File.open(@dir + '/' + file, "w") do |f|
|
54
|
+
f.puts(body)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
before :all do
|
59
|
+
require "tmpdir"
|
60
|
+
@dir = Dir.tmpdir + "/#{Time.now.to_i}" + "/annotate_models"
|
61
|
+
FileUtils.mkdir_p(@dir)
|
62
|
+
AnnotateModels.model_dir = @dir
|
63
|
+
create('foo.rb', <<-EOS)
|
64
|
+
class Foo < ActiveRecord::Base
|
65
|
+
end
|
66
|
+
EOS
|
67
|
+
create('foo_with_macro.rb', <<-EOS)
|
68
|
+
class FooWithMacro < ActiveRecord::Base
|
69
|
+
acts_as_awesome :yah
|
70
|
+
end
|
71
|
+
EOS
|
72
|
+
end
|
73
|
+
it "should work" do
|
74
|
+
klass = AnnotateModels.get_model_class("foo.rb")
|
75
|
+
klass.name.should == "Foo"
|
76
|
+
end
|
77
|
+
it "should not care about unknown macros" do
|
78
|
+
klass = AnnotateModels.get_model_class("foo_with_macro.rb")
|
79
|
+
klass.name.should == "FooWithMacro"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
43
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nofxx-annotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cuong Tran
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-08-21 00:00:00 -07:00
|
14
14
|
default_executable: annotate
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -27,7 +27,7 @@ files:
|
|
27
27
|
- History.txt
|
28
28
|
- README.rdoc
|
29
29
|
- Rakefile
|
30
|
-
- VERSION
|
30
|
+
- VERSION
|
31
31
|
- annotate.gemspec
|
32
32
|
- bin/annotate
|
33
33
|
- lib/annotate.rb
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- spec/spec_helper.rb
|
43
43
|
has_rdoc: false
|
44
44
|
homepage: http://github.com/nofxx/annotate
|
45
|
+
licenses:
|
45
46
|
post_install_message:
|
46
47
|
rdoc_options:
|
47
48
|
- --charset=UTF-8
|
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
requirements: []
|
63
64
|
|
64
65
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.
|
66
|
+
rubygems_version: 1.3.5
|
66
67
|
signing_key:
|
67
68
|
specification_version: 3
|
68
69
|
summary: Annotates Rails Models, routes, and others
|
data/VERSION.yml
DELETED