Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
annotate
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
annotate
Commits
277f1713
Commit
277f1713
authored
Mar 15, 2011
by
Rob Bevan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick hack to prefix annotation with encoding (encoding: UTF-8)
parent
9c68c8c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
annotate_models.rb
lib/annotate/annotate_models.rb
+13
-10
No files found.
lib/annotate/annotate_models.rb
View file @
277f1713
module
AnnotateModels
class
<<
self
UTF8
=
"encoding: UTF-8"
# Annotate Models plugin use this header
COMPAT_PREFIX
=
"== Schema Info"
PREFIX
=
"== Schema Information"
...
...
@@ -117,6 +119,7 @@ module AnnotateModels
def
annotate_one_file
(
file_name
,
info_block
,
options
=
{})
if
File
.
exist?
(
file_name
)
old_content
=
File
.
read
(
file_name
)
old_content
.
sub!
(
/^#
#{
UTF8
}
.*?\n/
,
''
)
# Ignore the Schema version line because it changes with each migration
header
=
Regexp
.
new
(
/(^# Table name:.*?\n(#.*\n)*\n)/
)
...
...
@@ -163,12 +166,12 @@ module AnnotateModels
if
annotate_one_file
(
model_file_name
,
info
,
options_with_position
(
options
,
:position_in_class
))
annotated
=
true
end
unless
ENV
[
'exclude_tests'
]
[
File
.
join
(
UNIT_TEST_DIR
,
"
#{
model_name
}
_test.rb"
),
# test
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
model_name
}
_spec.rb"
),
# spec
].
each
do
|
file
|
].
each
do
|
file
|
# todo: add an option "position_in_test" -- or maybe just ask if anyone ever wants different positions for model vs. test vs. fixture
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
end
...
...
@@ -179,21 +182,21 @@ module AnnotateModels
File
.
join
(
EXEMPLARS_TEST_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_SPEC_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
BLUEPRINTS_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
].
each
do
|
file
|
].
each
do
|
file
|
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
end
FIXTURE_DIRS
.
each
do
|
dir
|
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
if
File
.
exist?
(
fixture_file_name
)
annotate_one_file
(
fixture_file_name
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
annotate_one_file
(
fixture_file_name
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
end
end
end
annotated
end
# position = :position_in_fixture or :position_in_class
def
options_with_position
(
options
,
position_in
)
options
.
merge
(
:position
=>
(
options
[
position_in
]
||
options
[
:position
]))
...
...
@@ -248,7 +251,7 @@ module AnnotateModels
end
end
header
=
PREFIX
.
dup
header
=
"
#{
UTF8
.
dup
}
\n
#
#{
PREFIX
.
dup
}
"
if
options
[
:include_version
]
version
=
ActiveRecord
::
Migrator
.
current_version
rescue
0
...
...
@@ -274,7 +277,7 @@ module AnnotateModels
puts
"Unable to annotate
#{
file
}
:
#{
e
.
inspect
}
"
puts
""
# todo: check if all backtrace lines are in "gems" -- if so, it's an annotate bug, so print the whole stack trace.
# puts e.backtrace.join("\n\t")
# puts e.backtrace.join("\n\t")
end
end
if
annotated
.
empty?
...
...
@@ -303,12 +306,12 @@ module AnnotateModels
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
remove_annotation_of_file
(
fixture_file_name
)
if
File
.
exist?
(
fixture_file_name
)
end
[
File
.
join
(
UNIT_TEST_DIR
,
"
#{
klass
.
name
.
underscore
}
_test.rb"
),
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
klass
.
name
.
underscore
}
_spec.rb"
)].
each
do
|
file
|
remove_annotation_of_file
(
file
)
if
File
.
exist?
(
file
)
end
end
rescue
Exception
=>
e
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment