annotate 2.5.0 → 2.6.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{History.txt → CHANGELOG.rdoc} +62 -6
- data/README.rdoc +129 -39
- data/TODO.rdoc +12 -0
- data/annotate.gemspec +38 -0
- data/bin/annotate +66 -26
- data/lib/annotate.rb +143 -10
- data/lib/annotate/active_record_patch.rb +1 -1
- data/lib/annotate/annotate_models.rb +152 -98
- data/lib/annotate/annotate_routes.rb +126 -20
- data/lib/annotate/version.rb +1 -1
- data/lib/generators/{annotate_models → annotate}/USAGE +1 -1
- data/lib/generators/{annotate_models → annotate}/install_generator.rb +2 -2
- data/lib/generators/annotate/templates/auto_annotate_models.rake +34 -0
- data/lib/tasks/annotate_models.rake +21 -16
- data/lib/tasks/annotate_routes.rake +17 -2
- metadata +42 -29
- data/lib/generators/annotate_models/templates/auto_annotate_models.rake +0 -20
@@ -5,37 +5,143 @@
|
|
5
5
|
#
|
6
6
|
#
|
7
7
|
# Prepends the output of "rake routes" to the top of your routes.rb file.
|
8
|
-
# Yes, it's simple but I'm thick and often need a reminder of what my routes
|
8
|
+
# Yes, it's simple but I'm thick and often need a reminder of what my routes
|
9
|
+
# mean.
|
9
10
|
#
|
10
|
-
# Running this task will replace any exising route comment generated by the
|
11
|
-
# Best to back up your routes file before running:
|
11
|
+
# Running this task will replace any exising route comment generated by the
|
12
|
+
# task. Best to back up your routes file before running:
|
12
13
|
#
|
13
14
|
# Author:
|
14
15
|
# Gavin Montague
|
15
16
|
# gavin@leftbrained.co.uk
|
16
17
|
#
|
17
|
-
# Released under the same license as Ruby. No Support. No Warranty.
|
18
|
+
# Released under the same license as Ruby. No Support. No Warranty.
|
18
19
|
#
|
19
20
|
module AnnotateRoutes
|
20
|
-
PREFIX = "
|
21
|
-
|
22
|
-
def self.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
PREFIX = "# == Route Map"
|
22
|
+
|
23
|
+
def self.do_annotations(options={})
|
24
|
+
return unless(routes_exists?)
|
25
|
+
|
26
|
+
position_after = options[:position_in_routes] != 'before'
|
27
|
+
|
28
|
+
routes_map = `rake routes`.split(/\n/, -1)
|
29
|
+
|
30
|
+
# In old versions of Rake, the first line of output was the cwd. Not so
|
31
|
+
# much in newer ones. We ditch that line if it exists, and if not, we
|
32
|
+
# keep the line around.
|
33
|
+
routes_map.shift if(routes_map.first =~ /^\(in \//)
|
34
|
+
|
35
|
+
header = [
|
36
|
+
"#{PREFIX} (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})",
|
37
|
+
"#"
|
38
|
+
] + routes_map.map { |line| "# #{line}".rstrip }
|
39
|
+
|
40
|
+
(content, where_header_found) = strip_annotations(File.read(routes_file))
|
41
|
+
changed = where_header_found != 0 # This will either be :before, :after, or
|
42
|
+
# a number. If the number is > 0, the
|
43
|
+
# annotation was found somewhere in the
|
44
|
+
# middle of the file. If the number is
|
45
|
+
# zero, no annotation was found.
|
46
|
+
|
47
|
+
if(position_after)
|
48
|
+
# Ensure we have adequate trailing newlines at the end of the file to
|
49
|
+
# ensure a blank line separating the content from the annotation.
|
50
|
+
content << '' if(content.last != '')
|
51
|
+
|
52
|
+
# We're moving something from the top of the file to the bottom, so ditch
|
53
|
+
# the spacer we put in the first time around.
|
54
|
+
if(changed && where_header_found == :before)
|
55
|
+
content.shift if(content.first == '')
|
34
56
|
end
|
35
|
-
puts "Route file annotated."
|
36
57
|
else
|
37
|
-
|
58
|
+
header = header << '' if(content.first != '' || changed)
|
38
59
|
end
|
60
|
+
|
61
|
+
content = position_after ? (content + header) : header + content
|
62
|
+
|
63
|
+
write_contents(content)
|
64
|
+
|
65
|
+
puts "Route file annotated."
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.remove_annotations(options={})
|
69
|
+
return unless(routes_exists?)
|
70
|
+
|
71
|
+
(content, where_header_found) = strip_annotations(File.read(routes_file))
|
72
|
+
|
73
|
+
content = strip_on_removal(content, where_header_found)
|
74
|
+
|
75
|
+
write_contents(content)
|
76
|
+
|
77
|
+
puts "Removed annotations from routes file."
|
39
78
|
end
|
40
79
|
|
80
|
+
protected
|
81
|
+
|
82
|
+
def self.routes_file
|
83
|
+
@routes_rb ||= File.join("config", "routes.rb")
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.routes_exists?
|
87
|
+
routes_exists = File.exists?(routes_file)
|
88
|
+
puts "Can`t find routes.rb" if(!routes_exists)
|
89
|
+
return routes_exists
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.write_contents(content)
|
93
|
+
content << '' unless(content.last == '') # Make sure we end on a trailing
|
94
|
+
# newline.
|
95
|
+
|
96
|
+
File.open(routes_file, "wb") { |f| f.puts(content.join("\n")) }
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.strip_annotations(content)
|
100
|
+
real_content = []
|
101
|
+
mode = :content
|
102
|
+
line_number = 0
|
103
|
+
header_found_at = 0
|
104
|
+
content.split(/\n/, -1).each do |line|
|
105
|
+
line_number += 1
|
106
|
+
begin
|
107
|
+
if(mode == :header)
|
108
|
+
if(line !~ /\s*#/)
|
109
|
+
mode = :content
|
110
|
+
raise unless (line == '')
|
111
|
+
end
|
112
|
+
elsif(mode == :content)
|
113
|
+
if(line =~ /^\s*#\s*== Route.*$/)
|
114
|
+
header_found_at = line_number
|
115
|
+
mode = :header
|
116
|
+
else
|
117
|
+
real_content << line
|
118
|
+
end
|
119
|
+
end
|
120
|
+
rescue
|
121
|
+
retry
|
122
|
+
end
|
123
|
+
end
|
124
|
+
content_lines = real_content.count
|
125
|
+
|
126
|
+
# By default assume the annotation was found in the middle of the file...
|
127
|
+
where_header_found = header_found_at
|
128
|
+
# ... unless we have evidence it was at the beginning ...
|
129
|
+
where_header_found = :before if(header_found_at == 1)
|
130
|
+
# ... or that it was at the end.
|
131
|
+
where_header_found = :after if(header_found_at >= content_lines)
|
132
|
+
|
133
|
+
return real_content, where_header_found
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.strip_on_removal(content, where_header_found)
|
137
|
+
if(where_header_found == :before)
|
138
|
+
content.shift while(content.first == '')
|
139
|
+
elsif(where_header_found == :after)
|
140
|
+
content.pop while(content.last == '')
|
141
|
+
end
|
142
|
+
# TODO: If the user buried it in the middle, we should probably see about
|
143
|
+
# TODO: preserving a single line of space between the content above and
|
144
|
+
# TODO: below...
|
145
|
+
return content
|
146
|
+
end
|
41
147
|
end
|
data/lib/annotate/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# NOTE: only doing this in development as some production environments (Heroku)
|
2
|
+
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
|
3
|
+
# NOTE: to have a dev-mode tool do its thing in production.
|
4
|
+
if(Rails.env.development?)
|
5
|
+
task :set_annotation_options do
|
6
|
+
# You can override any of these by setting an environment variable of the
|
7
|
+
# same name.
|
8
|
+
Annotate.set_defaults({
|
9
|
+
'position_in_routes' => "before",
|
10
|
+
'position_in_class' => "before",
|
11
|
+
'position_in_test' => "before",
|
12
|
+
'position_in_fixture' => "before",
|
13
|
+
'position_in_factory' => "before",
|
14
|
+
'show_indexes' => "true",
|
15
|
+
'simple_indexes' => "false",
|
16
|
+
'model_dir' => "app/models",
|
17
|
+
'include_version' => "false",
|
18
|
+
'require' => "",
|
19
|
+
'exclude_tests' => "false",
|
20
|
+
'exclude_fixtures' => "false",
|
21
|
+
'exclude_factories' => "false",
|
22
|
+
'ignore_model_sub_dir' => "false",
|
23
|
+
'skip_on_db_migrate' => "false",
|
24
|
+
'format_bare' => "true",
|
25
|
+
'format_rdoc' => "false",
|
26
|
+
'format_markdown' => "false",
|
27
|
+
'sort' => "false",
|
28
|
+
'force' => "false",
|
29
|
+
'trace' => "false",
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
Annotate.load_tasks
|
34
|
+
end
|
@@ -10,25 +10,27 @@ task :annotate_models => :environment do
|
|
10
10
|
require "#{annotate_lib}/annotate/annotate_models"
|
11
11
|
require "#{annotate_lib}/annotate/active_record_patch"
|
12
12
|
|
13
|
-
true_re = /(true|t|yes|y|1)$/i
|
14
|
-
|
15
13
|
options={ :is_rake => true }
|
16
|
-
|
17
|
-
options[:
|
18
|
-
options[:
|
19
|
-
options[:
|
20
|
-
options[:
|
14
|
+
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
|
15
|
+
options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
|
16
|
+
options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
|
17
|
+
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
|
18
|
+
options[:position_in_test] = Annotate.fallback(ENV['position_in_test'], ENV['position'])
|
19
|
+
options[:show_indexes] = Annotate.true?(ENV['show_indexes'])
|
20
|
+
options[:simple_indexes] = Annotate.true?(ENV['simple_indexes'])
|
21
21
|
options[:model_dir] = ENV['model_dir']
|
22
|
-
options[:include_version] = ENV['include_version']
|
22
|
+
options[:include_version] = Annotate.true?(ENV['include_version'])
|
23
23
|
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
|
24
|
-
options[:exclude_tests] = ENV['exclude_tests']
|
25
|
-
options[:
|
26
|
-
options[:
|
27
|
-
options[:
|
28
|
-
options[:
|
29
|
-
options[:
|
30
|
-
options[:
|
31
|
-
options[:
|
24
|
+
options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])
|
25
|
+
options[:exclude_factories] = Annotate.true?(ENV['exclude_factories'])
|
26
|
+
options[:exclude_fixtures] = Annotate.true?(ENV['exclude_fixtures'])
|
27
|
+
options[:ignore_model_sub_dir] = Annotate.true?(ENV['ignore_model_sub_dir'])
|
28
|
+
options[:format_bare] = Annotate.true?(ENV['format_bare'])
|
29
|
+
options[:format_rdoc] = Annotate.true?(ENV['format_rdoc'])
|
30
|
+
options[:format_markdown] = Annotate.true?(ENV['format_markdown'])
|
31
|
+
options[:sort] = Annotate.true?(ENV['sort'])
|
32
|
+
options[:force] = Annotate.true?(ENV['force'])
|
33
|
+
options[:trace] = Annotate.true?(ENV['trace'])
|
32
34
|
AnnotateModels.do_annotations(options)
|
33
35
|
end
|
34
36
|
|
@@ -36,7 +38,10 @@ desc "Remove schema information from model and fixture files"
|
|
36
38
|
task :remove_annotation => :environment do
|
37
39
|
require "#{annotate_lib}/annotate/annotate_models"
|
38
40
|
require "#{annotate_lib}/annotate/active_record_patch"
|
41
|
+
|
39
42
|
options={ :is_rake => true }
|
40
43
|
options[:model_dir] = ENV['model_dir']
|
44
|
+
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
|
45
|
+
options[:trace] = Annotate.true?(ENV['trace'])
|
41
46
|
AnnotateModels.remove_annotations(options)
|
42
47
|
end
|
@@ -1,6 +1,21 @@
|
|
1
|
-
desc "
|
1
|
+
desc "Adds the route map to routes.rb"
|
2
2
|
task :annotate_routes => :environment do
|
3
3
|
annotate_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
4
4
|
require "#{annotate_lib}/annotate/annotate_routes"
|
5
|
-
|
5
|
+
|
6
|
+
options={}
|
7
|
+
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
|
8
|
+
options[:position_in_routes] = Annotate.fallback(ENV['position_in_routes'], ENV['position'])
|
9
|
+
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
|
10
|
+
AnnotateRoutes.do_annotations(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Removes the route map from routes.rb"
|
14
|
+
task :remove_routes => :environment do
|
15
|
+
annotate_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
16
|
+
require "#{annotate_lib}/annotate/annotate_routes"
|
17
|
+
|
18
|
+
options={}
|
19
|
+
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
|
20
|
+
AnnotateRoutes.remove_annotations(options)
|
6
21
|
end
|
metadata
CHANGED
@@ -1,35 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.6.0.beta2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Cuong Tran
|
9
8
|
- Alex Chaffee
|
10
9
|
- Marcos Piccinini
|
11
10
|
- Turadg Aleahmad
|
11
|
+
- Jon Frisby
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|
19
19
|
requirement: !ruby/object:Gem::Requirement
|
20
|
-
none: false
|
21
20
|
requirements:
|
22
|
-
- -
|
21
|
+
- - '>='
|
23
22
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
23
|
+
version: 0.8.7
|
25
24
|
type: :runtime
|
26
25
|
prerelease: false
|
27
26
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
27
|
requirements:
|
30
|
-
- -
|
28
|
+
- - '>='
|
31
29
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
30
|
+
version: 0.8.7
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: activerecord
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.3.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.3.0
|
33
45
|
description: Annotates Rails/ActiveRecord Models, routes, fixtures, and others based
|
34
46
|
on the database schema.
|
35
47
|
email:
|
@@ -37,55 +49,56 @@ email:
|
|
37
49
|
- ctran@pragmaquest.com
|
38
50
|
- x@nofxx.com
|
39
51
|
- turadg@aleahmad.net
|
52
|
+
- jon@cloudability.com
|
40
53
|
executables:
|
41
54
|
- annotate
|
42
55
|
extensions: []
|
43
56
|
extra_rdoc_files:
|
44
57
|
- README.rdoc
|
58
|
+
- CHANGELOG.rdoc
|
59
|
+
- TODO.rdoc
|
45
60
|
files:
|
61
|
+
- CHANGELOG.rdoc
|
46
62
|
- README.rdoc
|
47
|
-
-
|
48
|
-
-
|
49
|
-
|
63
|
+
- TODO.rdoc
|
64
|
+
- annotate.gemspec
|
65
|
+
- bin/annotate
|
66
|
+
- lib/annotate.rb
|
50
67
|
- lib/annotate/active_record_patch.rb
|
51
68
|
- lib/annotate/annotate_models.rb
|
52
69
|
- lib/annotate/annotate_routes.rb
|
53
70
|
- lib/annotate/tasks.rb
|
54
71
|
- lib/annotate/version.rb
|
55
|
-
- lib/annotate
|
56
|
-
- lib/generators/
|
57
|
-
- lib/generators/
|
58
|
-
- lib/generators/annotate_models/USAGE
|
72
|
+
- lib/generators/annotate/USAGE
|
73
|
+
- lib/generators/annotate/install_generator.rb
|
74
|
+
- lib/generators/annotate/templates/auto_annotate_models.rake
|
59
75
|
- lib/tasks/annotate_models.rake
|
60
76
|
- lib/tasks/annotate_routes.rake
|
61
77
|
- tasks/migrate.rake
|
62
78
|
homepage: http://github.com/ctran/annotate_models
|
63
|
-
licenses:
|
79
|
+
licenses:
|
80
|
+
- Ruby
|
81
|
+
metadata: {}
|
64
82
|
post_install_message:
|
65
|
-
rdoc_options:
|
66
|
-
- --charset=UTF-8
|
83
|
+
rdoc_options: []
|
67
84
|
require_paths:
|
68
85
|
- lib
|
69
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
87
|
requirements:
|
72
|
-
- -
|
88
|
+
- - '>='
|
73
89
|
- !ruby/object:Gem::Version
|
74
90
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: 3303794202298947958
|
78
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
92
|
requirements:
|
81
|
-
- -
|
93
|
+
- - '>'
|
82
94
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
95
|
+
version: 1.3.1
|
84
96
|
requirements: []
|
85
97
|
rubyforge_project: annotate
|
86
|
-
rubygems_version:
|
98
|
+
rubygems_version: 2.0.3
|
87
99
|
signing_key:
|
88
|
-
specification_version:
|
100
|
+
specification_version: 4
|
89
101
|
summary: Annotates Rails Models, routes, fixtures, and others based on the database
|
90
102
|
schema.
|
91
103
|
test_files: []
|
104
|
+
has_rdoc:
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# NOTE: only doing this in development as some production environments (Heroku)
|
2
|
-
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
|
3
|
-
# NOTE: to have a dev-mode tool do its thing in production.
|
4
|
-
if(Rails.env.development?)
|
5
|
-
task :set_annotation_options do
|
6
|
-
ENV['position_in_class'] = "before"
|
7
|
-
ENV['position_in_fixture'] = "before"
|
8
|
-
ENV['position_in_factory'] = "before"
|
9
|
-
ENV['show_indexes'] = "true"
|
10
|
-
ENV['include_version'] = "false"
|
11
|
-
ENV['exclude_tests'] = "false"
|
12
|
-
ENV['exclude_fixtures'] = "false"
|
13
|
-
ENV['ignore_model_sub_dir'] = "false"
|
14
|
-
ENV['skip_on_db_migrate'] = "false"
|
15
|
-
ENV['format_rdoc'] = "false"
|
16
|
-
ENV['format_markdown'] = "false"
|
17
|
-
ENV['no_sort'] = "false"
|
18
|
-
ENV['force'] = "false"
|
19
|
-
end
|
20
|
-
end
|