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
f50b4cca
Commit
f50b4cca
authored
Feb 05, 2010
by
Scott Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow :position => to be a symbol or string (as per the rake tasks)
parent
eac9f453
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+3
-1
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+19
-0
No files found.
lib/annotate/annotate_models.rb
View file @
f50b4cca
...
...
@@ -130,7 +130,9 @@ module AnnotateModels
old_content
.
sub!
(
/^#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
# Write it back
new_content
=
options
[
:position
]
==
'before'
?
(
info_block
+
old_content
)
:
(
old_content
+
"
\n
"
+
info_block
)
new_content
=
options
[
:position
].
to_sym
==
:before
?
(
info_block
+
old_content
)
:
(
old_content
+
"
\n
"
+
info_block
)
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
new_content
}
true
...
...
spec/annotate/annotate_models_spec.rb
View file @
f50b4cca
...
...
@@ -115,5 +115,24 @@ EOS
File
.
read
(
"user.rb"
).
should
==
"
#{
schema_info
}#{
file_content
}
\n
"
end
it
"should annotate before if given :position => :before"
do
file_content
=
"class User < ActiveRecord::Base; end"
File
.
open
(
"user.rb"
,
"w"
)
do
|
f
|
f
<<
file_content
end
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:name
,
:string
,
:limit
=>
50
)
])
schema_info
=
AnnotateModels
.
get_schema_info
(
klass
,
"Schema Info"
)
AnnotateModels
.
annotate_one_file
(
"user.rb"
,
schema_info
,
{
:position
=>
:before
})
File
.
read
(
"user.rb"
).
should
==
"
#{
schema_info
}#{
file_content
}
\n
"
end
end
end
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