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
84a9b0eb
Commit
84a9b0eb
authored
Dec 25, 2008
by
Marcos Augusto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Organize the code better/adds some tests
tagging 2.2.2
parent
0fd27ddc
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
97 additions
and
24 deletions
+97
-24
Manifest.txt
Manifest.txt
+12
-6
annotate.gemspec
annotate.gemspec
+2
-2
annotate.rb
lib/annotate.rb
+1
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+10
-6
annotate_routes.rb
lib/annotate/annotate_routes.rb
+2
-2
annotate_models.rake
lib/tasks/annotate_models.rake
+1
-1
annotate_routes.rake
lib/tasks/annotate_routes.rake
+1
-1
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+35
-0
annotate_routes_spec.rb
spec/annotate/annotate_routes_spec.rb
+30
-0
annotate_spec.rb
spec/annotate_spec.rb
+3
-5
No files found.
Manifest.txt
View file @
84a9b0eb
...
...
@@ -6,14 +6,16 @@ Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate
_models
/annotate_models.rb
lib/annotate
_routes
/annotate_routes.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
...
...
@@ -26,14 +28,16 @@ Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate
_models
/annotate_models.rb
lib/annotate
_routes
/annotate_routes.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
...
...
@@ -46,14 +50,16 @@ Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate
_models
/annotate_models.rb
lib/annotate
_routes
/annotate_routes.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
...
...
annotate.gemspec
View file @
84a9b0eb
...
...
@@ -2,7 +2,7 @@
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
%q{annotate}
s
.
version
=
"2.
1.1
"
s
.
version
=
"2.
2.2
"
s
.
required_rubygems_version
=
Gem
::
Requirement
.
new
(
">= 0"
)
if
s
.
respond_to?
:required_rubygems_version
=
s
.
authors
=
[
"Marcos Piccinini"
]
...
...
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s
.
email
=
[
"x@nofxx.com"
]
s
.
executables
=
[
"annotate"
]
s
.
extra_rdoc_files
=
[
"History.txt"
,
"License.txt"
,
"Manifest.txt"
,
"README.rdoc"
]
s
.
files
=
[
"History.txt"
,
"License.txt"
,
"Manifest.txt"
,
"README.rdoc"
,
"Rakefile"
,
"annotate.gemspec"
,
"bin/annotate"
,
"lib/annotate.rb"
,
"lib/annotate
_models/annotate_models.rb"
,
"lib/annotate_routes/annotate_routes.rb"
,
"lib/tasks/annotate_models.rake"
,
"lib/tasks/annotate_routes.rake"
,
"script/console"
,
"script/destroy"
,
"script/generate"
,
"setup
.rb"
,
"spec/annotate_spec.rb"
,
"spec/spec.opts"
,
"spec/spec_helper.rb"
,
"tasks/rspec.rake"
]
s
.
files
=
[
"History.txt"
,
"License.txt"
,
"Manifest.txt"
,
"README.rdoc"
,
"Rakefile"
,
"annotate.gemspec"
,
"bin/annotate"
,
"lib/annotate.rb"
,
"lib/annotate
/annotate_models.rb"
,
"lib/annotate/annotate_routes.rb"
,
"lib/tasks/annotate_models.rake"
,
"lib/tasks/annotate_routes.rake"
,
"script/console"
,
"script/destroy"
,
"script/generate"
,
"setup.rb"
,
"spec/annotate/annotate_models_spec.rb"
,
"spec/annotate/annotate_routes_spec
.rb"
,
"spec/annotate_spec.rb"
,
"spec/spec.opts"
,
"spec/spec_helper.rb"
,
"tasks/rspec.rake"
]
s
.
has_rdoc
=
true
s
.
homepage
=
%q{http://github.com/nofxx/annotate}
s
.
rdoc_options
=
[
"--main"
,
"README.rdoc"
]
...
...
lib/annotate.rb
View file @
84a9b0eb
...
...
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
$:
.
include?
(
File
.
dirname
(
__FILE__
))
||
$:
.
include?
(
File
.
expand_path
(
File
.
dirname
(
__FILE__
)))
module
Annotate
VERSION
=
'2.
1.1
'
VERSION
=
'2.
2.2
'
end
...
...
lib/annotate
_models
/annotate_models.rb
→
lib/annotate/annotate_models.rb
View file @
84a9b0eb
module
AnnotateModels
class
<<
self
# Annotate Models plugin use this header
COMPAT_PREFIX
=
"== Schema Info"
PREFIX
=
"== Schema Information"
MODEL_DIR
=
"app/models"
FIXTURE_DIRS
=
[
"test/fixtures"
,
"spec/fixtures"
]
UNIT_TEST_DIR
=
File
.
join
(
RAILS_ROOT
,
"test/unit"
)
SPEC_MODEL_DIR
=
File
.
join
(
RAILS_ROOT
,
"spec/models"
)
# File.join for windows reverse bar compat?
# I dont use windows, can`t test
UNIT_TEST_DIR
=
File
.
join
(
"test"
,
"unit"
)
SPEC_MODEL_DIR
=
File
.
join
(
"spec"
,
"models"
)
# Object Daddy http://github.com/flogic/object_daddy/tree/master
EXEMPLARS_DIR
=
File
.
join
(
RAILS_ROOT
,
"spec/exemplars"
)
PREFIX
=
"== Schema Information"
# Annotate Models as plugin use this header
COMPAT_PREFIX
=
"== Schema Info"
EXEMPLARS_DIR
=
File
.
join
(
"spec"
,
"exemplars"
)
# Simple quoting for the default column value
def
quote
(
value
)
...
...
lib/annotate
_routes
/annotate_routes.rb
→
lib/annotate/annotate_routes.rb
View file @
84a9b0eb
...
...
@@ -20,8 +20,8 @@ module AnnotateRoutes
PREFIX
=
"#== Route Info"
def
self
.
do_annotate
routes_rb
=
File
.
join
(
RAILS_ROOT
,
"config/
routes.rb"
)
header
=
PREFIX
+
"
\n
# Generated on
#{
Time
.
now
}
"
routes_rb
=
File
.
join
(
"config"
,
"
routes.rb"
)
header
=
PREFIX
+
"
\n
# Generated on
#{
Time
.
now
}
\n
#
"
if
File
.
exists?
routes_rb
routes_map
=
`rake routes`
routes_map
=
routes_map
.
split
(
"
\n
"
)
...
...
lib/tasks/annotate_models.rake
View file @
84a9b0eb
desc
"Add schema information (as comments) to model and fixture files"
task
:annotate_models
=>
:environment
do
require
'annotate
_models
/annotate_models'
require
'annotate/annotate_models'
options
=
{}
options
[
:position_in_class
]
=
ENV
[
'position_in_class'
]
||
ENV
[
'position'
]
options
[
:position_in_fixture
]
=
ENV
[
'position_in_fixture'
]
||
ENV
[
'position'
]
...
...
lib/tasks/annotate_routes.rake
View file @
84a9b0eb
desc
"Prepends the route map to the top of routes.rb"
task
:annotate_routes
do
require
'annotate
_routes
/annotate_routes'
require
'annotate/annotate_routes'
AnnotateRoutes
.
do_annotate
end
spec/annotate/annotate_models_spec.rb
0 → 100644
View file @
84a9b0eb
require
File
.
dirname
(
__FILE__
)
+
'/../spec_helper.rb'
require
'annotate/annotate_models'
describe
AnnotateModels
do
def
mock_klass
(
stubs
=
{})
@mock_file
||=
mock
(
"Klass"
,
stubs
)
end
def
mock_column
(
stubs
=
{})
@mock_column
||=
mock
(
"Column"
,
stubs
)
end
it
{
AnnotateModels
.
quote
(
nil
).
should
eql
(
"NULL"
)
}
it
{
AnnotateModels
.
quote
(
true
).
should
eql
(
"TRUE"
)
}
it
{
AnnotateModels
.
quote
(
false
).
should
eql
(
"FALSE"
)
}
it
{
AnnotateModels
.
quote
(
25
).
should
eql
(
"25"
)
}
it
{
AnnotateModels
.
quote
(
25.6
).
should
eql
(
"25.6"
)
}
it
{
AnnotateModels
.
quote
(
1
e
-
20
).
should
eql
(
"1.0e-20"
)
}
it
"should get schema info"
do
AnnotateModels
.
get_schema_info
(
mock_klass
(
:table_name
=>
"users"
,
:primary_key
=>
"id"
,
:column_names
=>
[
"id"
,
"login"
],
:columns
=>
[
mock_column
(
:type
=>
"integer"
,
:default
=>
nil
,
:null
=>
false
,
:name
=>
"id"
,
:limit
=>
nil
),
mock_column
(
:type
=>
"string"
,
:default
=>
nil
,
:null
=>
false
,
:name
=>
"name"
,
:limit
=>
50
)
]),
"Hello"
).
should
eql
(
"# Hello
\n
#
\n
# Table name: users
\n
#
\n
# id :integer not null, primary key
\n
# id :integer not null, primary key
\n
#
\n\n
"
)
end
end
spec/annotate/annotate_routes_spec.rb
0 → 100644
View file @
84a9b0eb
require
File
.
dirname
(
__FILE__
)
+
'/../spec_helper.rb'
require
'annotate/annotate_routes'
describe
AnnotateRoutes
do
def
mock_file
(
stubs
=
{})
@mock_file
||=
mock
(
File
,
stubs
)
end
it
"should check if routes.rb exists"
do
File
.
should_receive
(
:join
).
with
(
"config"
,
"routes.rb"
).
and_return
(
mock_file
)
File
.
should_receive
(
:exists?
).
with
(
@mock_file
).
and_return
(
false
)
AnnotateRoutes
.
should_receive
(
:puts
).
with
(
"Can`t find routes.rb"
)
AnnotateRoutes
.
do_annotate
end
it
"should annotate!"
do
File
.
should_receive
(
:join
).
with
(
"config"
,
"routes.rb"
).
and_return
(
"config/routes.rb"
)
File
.
should_receive
(
:exists?
).
with
(
"config/routes.rb"
).
and_return
(
true
)
AnnotateRoutes
.
should_receive
(
:`
).
with
(
"rake routes"
).
and_return
(
"bad line
\n
good line"
)
File
.
should_receive
(
:read
).
with
(
"config/routes.rb"
).
and_return
(
"bla"
)
File
.
should_receive
(
:open
).
with
(
"config/routes.rb"
,
"wb"
).
and_yield
(
mock_file
)
@mock_file
.
should_receive
(
:puts
).
with
(
/bla\n\n#== Route Info\n# Generated on .*\n#\n# good line/
)
AnnotateRoutes
.
do_annotate
end
end
spec/annotate_spec.rb
View file @
84a9b0eb
require
File
.
dirname
(
__FILE__
)
+
'/spec_helper.rb'
# Time to add your specs!
# http://rspec.info/
describe
"Place your specs here"
do
describe
Annotate
do
it
"
find this spec in spec directory
"
do
violated
"Be sure to write your specs"
it
"
should have a version
"
do
Annotate
::
VERSION
.
should
be_instance_of
(
String
)
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