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
d337abe0
Commit
d337abe0
authored
May 15, 2008
by
Henrik N
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only say "Annotated X, Y" for models where the annotation changed.
parent
bd7c0d22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
annotate_models.rb
lib/annotate_models.rb
+11
-6
No files found.
lib/annotate_models.rb
View file @
d337abe0
...
...
@@ -56,14 +56,17 @@ module AnnotateModels
#
def
annotate_one_file
(
file_name
,
info_block
,
options
=
{})
if
File
.
exist?
(
file_name
)
content
=
File
.
read
(
file_name
)
old_
content
=
File
.
read
(
file_name
)
# Remove old schema info
content
.
sub!
(
/^#
#{
PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
raw_content
=
old_content
.
sub
(
/^#
#{
PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
# Write it back
new_content
=
options
[
:position
]
==
"after"
?
(
content
+
info_block
)
:
(
info_block
+
content
)
new_content
=
options
[
:position
]
==
"after"
?
(
raw_content
+
info_block
)
:
(
info_block
+
raw_
content
)
File
.
open
(
file_name
,
"w"
)
{
|
f
|
f
.
puts
new_content
}
# Return whether the content changed
old_content
!=
new_content
end
end
...
...
@@ -86,12 +89,14 @@ module AnnotateModels
info
=
get_schema_info
(
klass
,
header
)
model_file_name
=
File
.
join
(
MODEL_DIR
,
file
)
annotate_one_file
(
model_file_name
,
info
,
options
.
merge
(
:position
=>
(
options
[
:position_in_class
]
||
options
[
:position
])))
content_changed
=
annotate_one_file
(
model_file_name
,
info
,
options
.
merge
(
:position
=>
(
options
[
:position_in_class
]
||
options
[
:position
])))
FIXTURE_DIRS
.
each
do
|
dir
|
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
annotate_one_file
(
fixture_file_name
,
info
,
options
.
merge
(
:position
=>
(
options
[
:position_in_fixture
]
||
options
[
:position
])))
if
File
.
exist?
(
fixture_file_name
)
end
content_changed
end
# Return a list of the model files to annotate. If we have
...
...
@@ -136,8 +141,8 @@ module AnnotateModels
begin
klass
=
get_model_class
(
file
)
if
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
annotate
(
klass
,
file
,
header
,
options
)
annotated
<<
klass
# Only append if the annotation changed
annotated
<<
klass
if
annotate
(
klass
,
file
,
header
,
options
)
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