annotator 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -4
- data/lib/annotator/initial_description/belongs_to.rb +1 -1
- data/lib/annotator/model.rb +14 -1
- data/lib/annotator/version.rb +1 -1
- data/test/annotator_test.rb +6 -0
- data/test/assets/boo_encoding.rb +5 -0
- data/test/assets/boo_encoding_annotated.rb +13 -0
- data/test/assets/moo_hoo_annotated.rb +2 -1
- metadata +102 -99
- data/lib/annotator/model.rb.orig +0 -66
data/README.rdoc
CHANGED
@@ -78,14 +78,19 @@ Contributions are very much welcome.
|
|
78
78
|
|
79
79
|
* since name does not have "model" in it, we could possibly use "rake routes" to annotate controller actions, not sure if it's worth it
|
80
80
|
|
81
|
-
==
|
81
|
+
== Credits
|
82
82
|
|
83
|
-
Kacper Cieśla @ Tech-Angels http://www.tech-angels.com
|
83
|
+
Kacper Cieśla @ Tech-Angels - http://www.tech-angels.com
|
84
84
|
|
85
|
-
|
85
|
+
{<img src="http://media.tumblr.com/tumblr_m5ay3bQiER1qa44ov.png" alt="Tech-Angels" />}[http://www.tech-angels.com]
|
86
|
+
|
87
|
+
{Contributions}[https://github.com/tech-angels/annotator/graphs/contributors]:
|
86
88
|
|
87
89
|
* {Lucas Florio}[https://github.com/lucasefe] - made it working without rails
|
88
90
|
|
91
|
+
|
89
92
|
== License
|
90
93
|
|
91
|
-
Annotator released under the MIT license.
|
94
|
+
Annotator is released under the MIT license.
|
95
|
+
|
96
|
+
|
@@ -7,7 +7,7 @@ module Annotator
|
|
7
7
|
def check
|
8
8
|
# check if there is belongs to association where this column is a foreign key
|
9
9
|
@model.reflect_on_all_associations.each do |reflection|
|
10
|
-
if reflection.foreign_key == @column && reflection.macro == :belongs_to
|
10
|
+
if (reflection.options[:foreign_key] || reflection.send(:derive_foreign_key)) == @column && reflection.macro == :belongs_to
|
11
11
|
@reflection = reflection
|
12
12
|
return true
|
13
13
|
end
|
data/lib/annotator/model.rb
CHANGED
@@ -33,7 +33,20 @@ module Annotator
|
|
33
33
|
@blocks[current_block] += [line]
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
|
37
|
+
# If there is no after block, it means there are no attributes block yet.
|
38
|
+
# Let's try to find some good place to insert them.
|
39
|
+
if @blocks[:after].empty?
|
40
|
+
@blocks[:before].each_with_index do |line,i|
|
41
|
+
# We want to insert them after requires or any comment block at the beginning of the file
|
42
|
+
unless line.match(/^require/) || line.match(/^#/)
|
43
|
+
@blocks[:after] = @blocks[:before][i..-1]
|
44
|
+
@blocks[:before] = (i == 0) ? [] : @blocks[:before][0..(i-1)] + [''] # add one additional separation line to make it cleaner
|
45
|
+
break
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
37
50
|
end
|
38
51
|
|
39
52
|
# If this file does not have associated AR class it should be skipped
|
data/lib/annotator/version.rb
CHANGED
data/test/annotator_test.rb
CHANGED
@@ -48,6 +48,12 @@ class AnnotatorTest < ActiveSupport::TestCase
|
|
48
48
|
assert_equal File.read(asset_file 'foo_require_first.rb' ), File.read(app_file 'foo.rb' )
|
49
49
|
end
|
50
50
|
|
51
|
+
test "leaving magic comments in place" do
|
52
|
+
FileUtils.cp asset_file('boo_encoding.rb'), app_file('boo.rb')
|
53
|
+
execute "rake annotate"
|
54
|
+
assert_equal File.read(asset_file 'boo_encoding_annotated.rb' ), File.read(app_file 'boo.rb' )
|
55
|
+
end
|
56
|
+
|
51
57
|
test "annotating namespaced models" do
|
52
58
|
assert_equal File.read(asset_file 'moo_hoo_annotated.rb' ), File.read(app_file 'moo/hoo.rb' )
|
53
59
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Attributes:
|
4
|
+
# * id [integer, primary, not null] - primary key
|
5
|
+
# * created_at [datetime, not null] - creation time
|
6
|
+
# * foo_id [integer] - belongs to :foo
|
7
|
+
# * poly_id [integer] - belongs to :poly (polymorphic)
|
8
|
+
# * poly_type [string] - belongs to :poly (polymorphic)
|
9
|
+
# * updated_at [datetime, not null] - last update time
|
10
|
+
class Boo < ActiveRecord::Base
|
11
|
+
belongs_to :foo
|
12
|
+
belongs_to :poly, :polymorphic => true
|
13
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# Some existing stupid comment
|
2
|
+
|
1
3
|
# Attributes:
|
2
4
|
# * id [integer, primary, not null] - primary key
|
3
5
|
# * body [text]
|
@@ -5,7 +7,6 @@
|
|
5
7
|
# * random_number [integer] - TODO: document me
|
6
8
|
# * title [string]
|
7
9
|
# * updated_at [datetime, not null] - last update time
|
8
|
-
# Some existing stupid comment
|
9
10
|
module Moo
|
10
11
|
class Hoo < ActiveRecord::Base
|
11
12
|
self.table_name = 'foos'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annotator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -69,84 +69,85 @@ extra_rdoc_files: []
|
|
69
69
|
files:
|
70
70
|
- lib/tasks/annotator_tasks.rake
|
71
71
|
- lib/annotator.rb
|
72
|
-
- lib/annotator/
|
72
|
+
- lib/annotator/railtie.rb
|
73
73
|
- lib/annotator/initial_description/devise.rb
|
74
|
-
- lib/annotator/initial_description/paperclip.rb
|
75
|
-
- lib/annotator/initial_description/base.rb
|
76
74
|
- lib/annotator/initial_description/rails.rb
|
77
|
-
- lib/annotator/
|
78
|
-
- lib/annotator/
|
75
|
+
- lib/annotator/initial_description/base.rb
|
76
|
+
- lib/annotator/initial_description/paperclip.rb
|
77
|
+
- lib/annotator/initial_description/belongs_to.rb
|
78
|
+
- lib/annotator/initial_description.rb
|
79
79
|
- lib/annotator/version.rb
|
80
80
|
- lib/annotator/attributes.rb
|
81
|
-
- lib/annotator/
|
82
|
-
- lib/annotator/railtie.rb
|
81
|
+
- lib/annotator/model.rb
|
83
82
|
- MIT-LICENSE
|
84
83
|
- Rakefile
|
85
84
|
- README.rdoc
|
86
|
-
- test/
|
87
|
-
- test/test_helper.rb
|
88
|
-
- test/assets/paper_annotated.rb
|
89
|
-
- test/assets/foo_annotated_bad_column.rb
|
90
|
-
- test/assets/foo_annotated_with_comments.rb
|
85
|
+
- test/assets/foo_require_first.rb
|
91
86
|
- test/assets/user_annotated.rb
|
92
|
-
- test/assets/
|
93
|
-
- test/assets/
|
87
|
+
- test/assets/moo_hoo_annotated.rb
|
88
|
+
- test/assets/boo_encoding_annotated.rb
|
89
|
+
- test/assets/boo_encoding.rb
|
94
90
|
- test/assets/foo_annotated.rb
|
91
|
+
- test/assets/foo_annotated_with_comments.rb
|
92
|
+
- test/assets/boo_annotated.rb
|
93
|
+
- test/assets/foo_annotated_bad_column_nodoc.rb
|
94
|
+
- test/assets/paper_annotated.rb
|
95
|
+
- test/assets/foo_annotated_bad_column.rb
|
95
96
|
- test/assets/foo_annotated_column_fixed.rb
|
96
|
-
- test/assets/foo_require_first.rb
|
97
|
-
- test/assets/moo_hoo_annotated.rb
|
98
97
|
- test/annotator_test.rb
|
99
|
-
- test/
|
100
|
-
- test/dummy/
|
101
|
-
- test/dummy/
|
102
|
-
- test/dummy/
|
103
|
-
- test/dummy/
|
104
|
-
- test/dummy/
|
98
|
+
- test/test_helper.rb
|
99
|
+
- test/dummy/app/helpers/application_helper.rb
|
100
|
+
- test/dummy/app/assets/stylesheets/application.css
|
101
|
+
- test/dummy/app/assets/javascripts/application.js
|
102
|
+
- test/dummy/app/controllers/application_controller.rb
|
103
|
+
- test/dummy/app/models/user.rb
|
104
|
+
- test/dummy/app/models/nomodel.rb
|
105
|
+
- test/dummy/app/models/foo.rb
|
106
|
+
- test/dummy/app/models/paper.rb
|
107
|
+
- test/dummy/app/models/moo/hoo.rb
|
108
|
+
- test/dummy/app/models/boo.rb
|
109
|
+
- test/dummy/app/views/layouts/application.html.erb
|
110
|
+
- test/dummy/config/routes.rb
|
111
|
+
- test/dummy/config/environment.rb
|
105
112
|
- test/dummy/config/environments/production.rb
|
106
113
|
- test/dummy/config/environments/development.rb
|
107
114
|
- test/dummy/config/environments/test.rb
|
108
115
|
- test/dummy/config/application.rb
|
116
|
+
- test/dummy/config/locales/en.yml
|
117
|
+
- test/dummy/config/database.yml
|
109
118
|
- test/dummy/config/boot.rb
|
110
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
111
119
|
- test/dummy/config/initializers/wrap_parameters.rb
|
112
|
-
- test/dummy/config/initializers/secret_token.rb
|
113
|
-
- test/dummy/config/initializers/session_store.rb
|
114
120
|
- test/dummy/config/initializers/mime_types.rb
|
121
|
+
- test/dummy/config/initializers/session_store.rb
|
122
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
123
|
+
- test/dummy/config/initializers/secret_token.rb
|
115
124
|
- test/dummy/config/initializers/inflections.rb
|
116
|
-
- test/dummy/
|
117
|
-
- test/dummy/config/environment.rb
|
118
|
-
- test/dummy/config/database.yml
|
125
|
+
- test/dummy/script/rails
|
119
126
|
- test/dummy/log/development.log
|
120
127
|
- test/dummy/log/test.log
|
121
|
-
- test/dummy/app/helpers/application_helper.rb
|
122
|
-
- test/dummy/app/models/boo.rb
|
123
|
-
- test/dummy/app/models/paper.rb
|
124
|
-
- test/dummy/app/models/moo/hoo.rb
|
125
|
-
- test/dummy/app/models/user.rb
|
126
|
-
- test/dummy/app/models/foo.rb
|
127
|
-
- test/dummy/app/models/nomodel.rb
|
128
|
-
- test/dummy/app/views/layouts/application.html.erb
|
129
|
-
- test/dummy/app/assets/javascripts/application.js
|
130
|
-
- test/dummy/app/assets/stylesheets/application.css
|
131
|
-
- test/dummy/app/controllers/application_controller.rb
|
132
128
|
- test/dummy/config.ru
|
133
|
-
- test/dummy/
|
134
|
-
- test/dummy/
|
135
|
-
- test/dummy/
|
136
|
-
- test/dummy/
|
137
|
-
- test/dummy/
|
129
|
+
- test/dummy/Rakefile
|
130
|
+
- test/dummy/db/development.sqlite3
|
131
|
+
- test/dummy/db/migrate/20120527023350_create_papers.rb
|
132
|
+
- test/dummy/db/migrate/20120527020350_devise_create_users.rb
|
133
|
+
- test/dummy/db/migrate/20120527023417_add_attachment_avatar_to_papers.rb
|
134
|
+
- test/dummy/db/migrate/20120219112425_create_foos.rb
|
135
|
+
- test/dummy/db/migrate/20120527025142_create_boos.rb
|
136
|
+
- test/dummy/db/schema.rb
|
137
|
+
- test/dummy/test/fixtures/boos.yml
|
138
138
|
- test/dummy/test/fixtures/papers.yml
|
139
139
|
- test/dummy/test/fixtures/users.yml
|
140
140
|
- test/dummy/test/fixtures/foos.yml
|
141
|
-
- test/dummy/test/
|
141
|
+
- test/dummy/test/unit/paper_test.rb
|
142
|
+
- test/dummy/test/unit/boo_test.rb
|
143
|
+
- test/dummy/test/unit/user_test.rb
|
144
|
+
- test/dummy/test/unit/foo_test.rb
|
142
145
|
- test/dummy/README.rdoc
|
143
|
-
- test/dummy/
|
144
|
-
- test/dummy/
|
145
|
-
- test/dummy/
|
146
|
-
- test/dummy/
|
147
|
-
- test/
|
148
|
-
- test/dummy/db/migrate/20120219112425_create_foos.rb
|
149
|
-
- test/dummy/db/development.sqlite3
|
146
|
+
- test/dummy/public/favicon.ico
|
147
|
+
- test/dummy/public/404.html
|
148
|
+
- test/dummy/public/500.html
|
149
|
+
- test/dummy/public/422.html
|
150
|
+
- test/support/test_app.rb
|
150
151
|
homepage: https://github.com/tech-angels/annotator
|
151
152
|
licenses: []
|
152
153
|
post_install_message:
|
@@ -172,67 +173,69 @@ signing_key:
|
|
172
173
|
specification_version: 3
|
173
174
|
summary: Annotate your models and keep your comments about fields.
|
174
175
|
test_files:
|
175
|
-
- test/
|
176
|
-
- test/test_helper.rb
|
177
|
-
- test/assets/paper_annotated.rb
|
178
|
-
- test/assets/foo_annotated_bad_column.rb
|
179
|
-
- test/assets/foo_annotated_with_comments.rb
|
176
|
+
- test/assets/foo_require_first.rb
|
180
177
|
- test/assets/user_annotated.rb
|
181
|
-
- test/assets/
|
182
|
-
- test/assets/
|
178
|
+
- test/assets/moo_hoo_annotated.rb
|
179
|
+
- test/assets/boo_encoding_annotated.rb
|
180
|
+
- test/assets/boo_encoding.rb
|
183
181
|
- test/assets/foo_annotated.rb
|
182
|
+
- test/assets/foo_annotated_with_comments.rb
|
183
|
+
- test/assets/boo_annotated.rb
|
184
|
+
- test/assets/foo_annotated_bad_column_nodoc.rb
|
185
|
+
- test/assets/paper_annotated.rb
|
186
|
+
- test/assets/foo_annotated_bad_column.rb
|
184
187
|
- test/assets/foo_annotated_column_fixed.rb
|
185
|
-
- test/assets/foo_require_first.rb
|
186
|
-
- test/assets/moo_hoo_annotated.rb
|
187
188
|
- test/annotator_test.rb
|
188
|
-
- test/
|
189
|
-
- test/dummy/
|
190
|
-
- test/dummy/
|
191
|
-
- test/dummy/
|
192
|
-
- test/dummy/
|
193
|
-
- test/dummy/
|
189
|
+
- test/test_helper.rb
|
190
|
+
- test/dummy/app/helpers/application_helper.rb
|
191
|
+
- test/dummy/app/assets/stylesheets/application.css
|
192
|
+
- test/dummy/app/assets/javascripts/application.js
|
193
|
+
- test/dummy/app/controllers/application_controller.rb
|
194
|
+
- test/dummy/app/models/user.rb
|
195
|
+
- test/dummy/app/models/nomodel.rb
|
196
|
+
- test/dummy/app/models/foo.rb
|
197
|
+
- test/dummy/app/models/paper.rb
|
198
|
+
- test/dummy/app/models/moo/hoo.rb
|
199
|
+
- test/dummy/app/models/boo.rb
|
200
|
+
- test/dummy/app/views/layouts/application.html.erb
|
201
|
+
- test/dummy/config/routes.rb
|
202
|
+
- test/dummy/config/environment.rb
|
194
203
|
- test/dummy/config/environments/production.rb
|
195
204
|
- test/dummy/config/environments/development.rb
|
196
205
|
- test/dummy/config/environments/test.rb
|
197
206
|
- test/dummy/config/application.rb
|
207
|
+
- test/dummy/config/locales/en.yml
|
208
|
+
- test/dummy/config/database.yml
|
198
209
|
- test/dummy/config/boot.rb
|
199
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
200
210
|
- test/dummy/config/initializers/wrap_parameters.rb
|
201
|
-
- test/dummy/config/initializers/secret_token.rb
|
202
|
-
- test/dummy/config/initializers/session_store.rb
|
203
211
|
- test/dummy/config/initializers/mime_types.rb
|
212
|
+
- test/dummy/config/initializers/session_store.rb
|
213
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
214
|
+
- test/dummy/config/initializers/secret_token.rb
|
204
215
|
- test/dummy/config/initializers/inflections.rb
|
205
|
-
- test/dummy/
|
206
|
-
- test/dummy/config/environment.rb
|
207
|
-
- test/dummy/config/database.yml
|
216
|
+
- test/dummy/script/rails
|
208
217
|
- test/dummy/log/development.log
|
209
218
|
- test/dummy/log/test.log
|
210
|
-
- test/dummy/app/helpers/application_helper.rb
|
211
|
-
- test/dummy/app/models/boo.rb
|
212
|
-
- test/dummy/app/models/paper.rb
|
213
|
-
- test/dummy/app/models/moo/hoo.rb
|
214
|
-
- test/dummy/app/models/user.rb
|
215
|
-
- test/dummy/app/models/foo.rb
|
216
|
-
- test/dummy/app/models/nomodel.rb
|
217
|
-
- test/dummy/app/views/layouts/application.html.erb
|
218
|
-
- test/dummy/app/assets/javascripts/application.js
|
219
|
-
- test/dummy/app/assets/stylesheets/application.css
|
220
|
-
- test/dummy/app/controllers/application_controller.rb
|
221
219
|
- test/dummy/config.ru
|
222
|
-
- test/dummy/
|
223
|
-
- test/dummy/
|
224
|
-
- test/dummy/
|
225
|
-
- test/dummy/
|
226
|
-
- test/dummy/
|
220
|
+
- test/dummy/Rakefile
|
221
|
+
- test/dummy/db/development.sqlite3
|
222
|
+
- test/dummy/db/migrate/20120527023350_create_papers.rb
|
223
|
+
- test/dummy/db/migrate/20120527020350_devise_create_users.rb
|
224
|
+
- test/dummy/db/migrate/20120527023417_add_attachment_avatar_to_papers.rb
|
225
|
+
- test/dummy/db/migrate/20120219112425_create_foos.rb
|
226
|
+
- test/dummy/db/migrate/20120527025142_create_boos.rb
|
227
|
+
- test/dummy/db/schema.rb
|
228
|
+
- test/dummy/test/fixtures/boos.yml
|
227
229
|
- test/dummy/test/fixtures/papers.yml
|
228
230
|
- test/dummy/test/fixtures/users.yml
|
229
231
|
- test/dummy/test/fixtures/foos.yml
|
230
|
-
- test/dummy/test/
|
232
|
+
- test/dummy/test/unit/paper_test.rb
|
233
|
+
- test/dummy/test/unit/boo_test.rb
|
234
|
+
- test/dummy/test/unit/user_test.rb
|
235
|
+
- test/dummy/test/unit/foo_test.rb
|
231
236
|
- test/dummy/README.rdoc
|
232
|
-
- test/dummy/
|
233
|
-
- test/dummy/
|
234
|
-
- test/dummy/
|
235
|
-
- test/dummy/
|
236
|
-
- test/
|
237
|
-
- test/dummy/db/migrate/20120219112425_create_foos.rb
|
238
|
-
- test/dummy/db/development.sqlite3
|
237
|
+
- test/dummy/public/favicon.ico
|
238
|
+
- test/dummy/public/404.html
|
239
|
+
- test/dummy/public/500.html
|
240
|
+
- test/dummy/public/422.html
|
241
|
+
- test/support/test_app.rb
|
data/lib/annotator/model.rb.orig
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module Annotator
|
2
|
-
|
3
|
-
# Represents a single model file and associated class
|
4
|
-
class Model
|
5
|
-
|
6
|
-
def initialize(filename, base_path)
|
7
|
-
@filename = filename
|
8
|
-
@base_path = base_path
|
9
|
-
@blocks = Hash.new {[]}
|
10
|
-
end
|
11
|
-
|
12
|
-
# Model class
|
13
|
-
def klass
|
14
|
-
<<<<<<< HEAD
|
15
|
-
begin
|
16
|
-
@filename.split('app/models/').last.split(/\.rb$/).first.camelize.constantize
|
17
|
-
rescue Exception
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
=======
|
21
|
-
@filename.split(@base_path).last.split(/\.rb$/).first.camelize.constantize rescue nil
|
22
|
-
>>>>>>> lucasefe/master
|
23
|
-
end
|
24
|
-
|
25
|
-
# Split file into 3 blocks: before attributes, attributes block, and after
|
26
|
-
# If there's no attributes block, content will be in :after part (for easier insertion)
|
27
|
-
def parse
|
28
|
-
@file = File.read(@filename).strip
|
29
|
-
current_block = :before
|
30
|
-
return @nodoc = true if @file.match(/^# Attributes\(nodoc\):$/i)
|
31
|
-
@file.split("\n").each do |line|
|
32
|
-
if line.match(/^#{Regexp.escape Attributes::HEADER} *$/)
|
33
|
-
current_block = :attributes
|
34
|
-
next
|
35
|
-
end
|
36
|
-
current_block = :after if current_block == :attributes && !line.match(Attributes::R_ATTRIBUTE_LINE)
|
37
|
-
@blocks[current_block] += [line]
|
38
|
-
end
|
39
|
-
|
40
|
-
@blocks[:after], @blocks[:before] = @blocks[:before], [] if @blocks[:after].empty?
|
41
|
-
end
|
42
|
-
|
43
|
-
# If this file does not have associated AR class it should be skipped
|
44
|
-
def skipped?
|
45
|
-
!klass || !klass.ancestors.include?(ActiveRecord::Base) || @nodoc
|
46
|
-
end
|
47
|
-
|
48
|
-
# Save changes to file if there were any
|
49
|
-
def update_file
|
50
|
-
output = (@blocks[:before] + @blocks[:attributes] + @blocks[:after]).join("\n").strip + "\n"
|
51
|
-
File.open(@filename,'w') { |f| f.write(output) } if output != @file
|
52
|
-
end
|
53
|
-
|
54
|
-
# Update file with new database information
|
55
|
-
def update!
|
56
|
-
parse
|
57
|
-
return true if skipped?
|
58
|
-
attributes = Attributes.new klass, @blocks[:attributes]
|
59
|
-
attributes.update!
|
60
|
-
@blocks[:attributes] = attributes.lines
|
61
|
-
update_file
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
|