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
809a29f9
Commit
809a29f9
authored
Feb 29, 2012
by
Jon Frisby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing behavior with some model sub-classes, adding skip-annotations feature.
parent
70206842
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
+12
-4
History.txt
History.txt
+2
-0
README.rdoc
README.rdoc
+5
-0
annotate_models.rb
lib/annotate/annotate_models.rb
+5
-4
No files found.
History.txt
View file @
809a29f9
== HEAD
* Add ability to skip annotations for a model by adding
'# -*- SkipSchemaAnnotations' anywhere in the file.
* Don't show column limits for integer and boolean types.
* Add sorting for columns and indexes. (Helpful for out-of-order migration
execution!)
...
...
README.rdoc
View file @
809a29f9
...
...
@@ -85,6 +85,11 @@ This will produce a .rake file that will ensure annotation happens after
migration (but only in development mode), and provide configuration options
you can use to tailor the output.
If you want to always skip annotations on a particular model, add this string
anywhere in the file:
# -*- SkipSchemaAnnotations
== OPTIONS
Usage: annotate_models [options] [model_file]*
...
...
lib/annotate/annotate_models.rb
View file @
809a29f9
...
...
@@ -146,6 +146,7 @@ module AnnotateModels
def
annotate_one_file
(
file_name
,
info_block
,
options
=
{})
if
File
.
exist?
(
file_name
)
old_content
=
File
.
read
(
file_name
)
return
false
if
(
old_content
=~
/# -\*- SkipSchemaAnnotations.*\n/
)
# Ignore the Schema version line because it changes with each migration
header_pattern
=
/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/
...
...
@@ -269,7 +270,7 @@ module AnnotateModels
# in subdirectories without namespacing.
def
get_model_class
(
file
)
# this is for non-rails projects, which don't get Rails auto-require magic
require
File
.
expand_path
(
"
#{
model_dir
}
/
#{
file
}
"
)
unless
Module
.
const_defined?
(
:Rails
)
require
File
.
expand_path
(
"
#{
model_dir
}
/
#{
file
}
"
)
model_path
=
file
.
gsub
(
/\.rb$/
,
''
)
get_loaded_model
(
model_path
)
||
get_loaded_model
(
model_path
.
split
(
'/'
).
last
)
...
...
@@ -277,9 +278,9 @@ module AnnotateModels
# Retrieve loaded model class by path to the file where it's supposed to be defined.
def
get_loaded_model
(
model_path
)
ObjectSpace
.
each_object
(
class
<<
ActiveRecord
::
Base
;
self
;
end
).
detect
do
|
c
|
ActiveSupport
::
Inflector
.
underscore
(
c
)
==
model_path
end
ObjectSpace
.
each_object
.
select
{
|
c
|
c
.
is_a?
(
Class
)
&&
c
.
ancestors
.
include?
(
ActiveRecord
::
Base
)
}.
detect
{
|
c
|
ActiveSupport
::
Inflector
.
underscore
(
c
)
==
model_path
}
end
# We're passed a name of things that might be
...
...
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