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
9ce1fd65
Commit
9ce1fd65
authored
Sep 15, 2011
by
Cuong Tran
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #48 from rtlong/master
Implement FactoryGirl
parents
634b6ac1
a645dc4e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
9 deletions
+22
-9
annotate_models.rb
lib/annotate/annotate_models.rb
+22
-9
No files found.
lib/annotate/annotate_models.rb
View file @
9ce1fd65
...
@@ -9,11 +9,15 @@ module AnnotateModels
...
@@ -9,11 +9,15 @@ module AnnotateModels
# I dont use windows, can`t test
# I dont use windows, can`t test
UNIT_TEST_DIR
=
File
.
join
(
"test"
,
"unit"
)
UNIT_TEST_DIR
=
File
.
join
(
"test"
,
"unit"
)
SPEC_MODEL_DIR
=
File
.
join
(
"spec"
,
"models"
)
SPEC_MODEL_DIR
=
File
.
join
(
"spec"
,
"models"
)
# Object Daddy http://github.com/flogic/object_daddy
/tree/master
# Object Daddy http://github.com/flogic/object_daddy
EXEMPLARS_TEST_DIR
=
File
.
join
(
"test"
,
"exemplars"
)
EXEMPLARS_TEST_DIR
=
File
.
join
(
"test"
,
"exemplars"
)
EXEMPLARS_SPEC_DIR
=
File
.
join
(
"spec"
,
"exemplars"
)
EXEMPLARS_SPEC_DIR
=
File
.
join
(
"spec"
,
"exemplars"
)
# Machinist http://github.com/notahat/machinist
# Machinist http://github.com/notahat/machinist
BLUEPRINTS_DIR
=
File
.
join
(
"test"
,
"blueprints"
)
BLUEPRINTS_DIR
=
File
.
join
(
"test"
,
"blueprints"
)
# FactoryGirl http://github.com/thoughtbot/factory_girl
FACTORIES_TEST_DIR
=
File
.
join
(
"test"
,
"factories"
)
FACTORIES_SPEC_DIR
=
File
.
join
(
"spec"
,
"factories"
)
def
model_dir
def
model_dir
@model_dir
||
"app/models"
@model_dir
||
"app/models"
...
@@ -119,12 +123,13 @@ module AnnotateModels
...
@@ -119,12 +123,13 @@ module AnnotateModels
old_content
=
File
.
read
(
file_name
)
old_content
=
File
.
read
(
file_name
)
# Ignore the Schema version line because it changes with each migration
# Ignore the Schema version line because it changes with each migration
header
=
Regexp
.
new
(
/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/
)
header
_pattern
=
/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/
old_header
=
old_content
.
match
(
header
).
to_s
old_header
=
old_content
.
match
(
header
_pattern
).
to_s
new_header
=
info_block
.
match
(
header
).
to_s
new_header
=
info_block
.
match
(
header
_pattern
).
to_s
old_columns
=
old_header
&&
old_header
.
scan
(
/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/
).
sort
column_pattern
=
/^#[\t ]+\w+[\t ]+:\w+/
new_columns
=
new_header
&&
new_header
.
scan
(
/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/
).
sort
old_columns
=
old_header
&&
old_header
.
scan
(
column_pattern
).
sort
new_columns
=
new_header
&&
new_header
.
scan
(
column_pattern
).
sort
if
old_columns
==
new_columns
if
old_columns
==
new_columns
false
false
...
@@ -176,7 +181,9 @@ module AnnotateModels
...
@@ -176,7 +181,9 @@ module AnnotateModels
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
model_name
}
_spec.rb"
),
# spec
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
# 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
))
if
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
annotated
=
true
end
end
end
end
end
...
@@ -185,14 +192,20 @@ module AnnotateModels
...
@@ -185,14 +192,20 @@ module AnnotateModels
File
.
join
(
EXEMPLARS_TEST_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_TEST_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_SPEC_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
File
.
join
(
BLUEPRINTS_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
File
.
join
(
FACTORIES_TEST_DIR
,
"
#{
model_name
.
pluralize
}
.rb"
),
# FactoryGirl Factories
File
.
join
(
FACTORIES_SPEC_DIR
,
"
#{
model_name
.
pluralize
}
.rb"
),
# FactoryGirl Factories
].
each
do
|
file
|
].
each
do
|
file
|
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
if
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
annotated
=
true
end
end
end
FIXTURE_DIRS
.
each
do
|
dir
|
FIXTURE_DIRS
.
each
do
|
dir
|
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
if
File
.
exist?
(
fixture_file_name
)
if
File
.
exist?
(
fixture_file_name
)
annotate_one_file
(
fixture_file_name
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
if
annotate_one_file
(
fixture_file_name
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
annotated
=
true
end
end
end
end
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