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
28a44896
Commit
28a44896
authored
Apr 30, 2009
by
Alex Chaffee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes to support non-Rails projects: make 'model_dir' a parameter; require model files
parent
4aee03d3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
8 deletions
+28
-8
annotate
bin/annotate
+1
-0
annotate_models.rb
lib/annotate/annotate_models.rb
+20
-6
annotate.rake
lib/tasks/annotate.rake
+5
-1
annotate_models.rake
lib/tasks/annotate_models.rake
+1
-0
test_helper.rb
test/test_helper.rb
+1
-1
No files found.
bin/annotate
View file @
28a44896
...
...
@@ -12,6 +12,7 @@ OptionParser.new do |opts|
opts
.
on
(
'-r'
,
'--routes'
)
{
task
=
:annotate_routes
}
opts
.
on
(
'-v'
,
'--version'
)
{
puts
"Annotate v
#{
Annotate
::
VERSION
}
"
;
exit
}
opts
.
on
(
'-m'
,
'--show-migration'
)
{
ENV
[
'include_version'
]
=
"yes"
}
opts
.
on
(
'-l'
,
'--model-dir dir'
)
{
|
dir
|
ENV
[
'model_dir'
]
=
dir
}
end
.
parse!
begin
...
...
lib/annotate/annotate_models.rb
View file @
28a44896
...
...
@@ -4,7 +4,6 @@ module AnnotateModels
COMPAT_PREFIX
=
"== Schema Info"
PREFIX
=
"== Schema Information"
MODEL_DIR
=
"app/models"
FIXTURE_DIRS
=
[
"test/fixtures"
,
"spec/fixtures"
]
# File.join for windows reverse bar compat?
# I dont use windows, can`t test
...
...
@@ -13,6 +12,13 @@ module AnnotateModels
# Object Daddy http://github.com/flogic/object_daddy/tree/master
EXEMPLARS_DIR
=
File
.
join
(
"spec"
,
"exemplars"
)
def
model_dir
@model_dir
||
"app/models"
end
def
model_dir
=
(
dir
)
@model_dir
=
dir
end
# Simple quoting for the default column value
def
quote
(
value
)
...
...
@@ -119,7 +125,7 @@ module AnnotateModels
info
=
get_schema_info
(
klass
,
header
)
annotated
=
false
model_name
=
klass
.
name
.
underscore
model_file_name
=
File
.
join
(
MODEL_DIR
,
file
)
model_file_name
=
File
.
join
(
model_dir
,
file
)
if
annotate_one_file
(
model_file_name
,
info
,
options
.
merge
(
:position
=>
(
options
[
:position_in_class
]
||
options
[
:position
])))
annotated
=
true
...
...
@@ -142,13 +148,13 @@ module AnnotateModels
# command line arguments, they're assumed to be either
# the underscore or CamelCase versions of model names.
# Otherwise we take all the model files in the
#
app/models
directory.
#
model_dir
directory.
def
get_model_files
models
=
ARGV
.
dup
models
.
shift
models
.
reject!
{
|
m
|
m
.
starts_with?
(
"position="
)}
if
models
.
empty?
Dir
.
chdir
(
MODEL_DIR
)
do
Dir
.
chdir
(
model_dir
)
do
models
=
Dir
[
"**/*.rb"
]
end
end
...
...
@@ -159,6 +165,7 @@ module AnnotateModels
# Check for namespaced models in subdirectories as well as models
# in subdirectories without namespacing.
def
get_model_class
(
file
)
require
"
#{
model_dir
}
/
#{
file
}
"
model
=
file
.
gsub
(
/\.rb$/
,
''
).
camelize
parts
=
model
.
split
(
'::'
)
begin
...
...
@@ -181,6 +188,10 @@ module AnnotateModels
header
<<
"
\n
# Schema version:
#{
version
}
"
end
end
if
options
[
:model_dir
]
self
.
model_dir
=
options
[
:model_dir
]
end
annotated
=
[]
get_model_files
.
each
do
|
file
|
...
...
@@ -202,7 +213,10 @@ module AnnotateModels
end
end
def
remove_annotations
def
remove_annotations
(
options
=
{})
if
options
[
:model_dir
]
self
.
model_dir
=
options
[
:model_dir
]
end
deannotated
=
[]
get_model_files
.
each
do
|
file
|
begin
...
...
@@ -210,7 +224,7 @@ module AnnotateModels
if
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
deannotated
<<
klass
model_file_name
=
File
.
join
(
MODEL_DIR
,
file
)
model_file_name
=
File
.
join
(
model_dir
,
file
)
remove_annotation_of_file
(
model_file_name
)
FIXTURE_DIRS
.
each
do
|
dir
|
...
...
lib/tasks/annotate.rake
View file @
28a44896
...
...
@@ -5,11 +5,14 @@ task :annotate_models => :environment do
options
[
:position_in_class
]
=
ENV
[
'position_in_class'
]
||
ENV
[
'position'
]
options
[
:position_in_fixture
]
=
ENV
[
'position_in_fixture'
]
||
ENV
[
'position'
]
options
[
:include_version
]
=
ENV
[
'include_version'
]
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
AnnotateModels
.
do_annotations
(
options
)
end
desc
"Remove schema information from model and fixture files"
task
:remove_annotation
=>
:environment
do
require
'annotate_models'
AnnotateModels
.
remove_annotations
options
=
{}
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
AnnotateModels
.
remove_annotations
(
options
)
end
\ No newline at end of file
lib/tasks/annotate_models.rake
View file @
28a44896
...
...
@@ -4,6 +4,7 @@ task :annotate_models => :environment do
options
=
{}
options
[
:position_in_class
]
=
ENV
[
'position_in_class'
]
||
ENV
[
'position'
]
||
:before
options
[
:position_in_fixture
]
=
ENV
[
'position_in_fixture'
]
||
ENV
[
'position'
]
||
:before
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
AnnotateModels
.
do_annotations
(
options
)
end
...
...
test/test_helper.rb
View file @
28a44896
require
'test/unit'
require
File
.
dirname
(
__FILE__
)
+
'/../lib/annotate
_models
'
require
File
.
dirname
(
__FILE__
)
+
'/../lib/annotate'
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