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
e1f6eafd
Commit
e1f6eafd
authored
8 years ago
by
Guillermo Guerrero Ibarra
Committed by
Cuong Tran
8 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix offences and added test (#425)
* Fixed some offenses * Added test.
parent
c407ed6a
develop
…
v3.2.0
v3.1.1
v3.1.1-release
v3.1.0
v3.0.3
v3.0.2
v3.0.0
v2.7.5
v2.7.4
v2.7.3
v2.7.2
release/v3.0.1
No related merge requests found
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
52 deletions
+55
-52
.rubocop_todo.yml
.rubocop_todo.yml
+0
-0
annotate
bin/annotate
+6
-5
annotate.rb
lib/annotate.rb
+16
-10
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+0
-0
common_validation.rb
spec/integration/common_validation.rb
+26
-31
integration_spec.rb
spec/integration/integration_spec.rb
+5
-4
rails_3.2.8.rb
spec/integration/rails_3.2.8.rb
+2
-2
No files found.
.rubocop_todo.yml
View file @
e1f6eafd
This diff is collapsed.
Click to expand it.
bin/annotate
View file @
e1f6eafd
...
@@ -8,11 +8,11 @@ require 'rubygems'
...
@@ -8,11 +8,11 @@ require 'rubygems'
begin
begin
require
'bundler'
require
'bundler'
Bundler
.
setup
Bundler
.
setup
rescue
Exception
rescue
StandardError
end
end
here
=
File
.
expand_path
(
File
.
dirname
__FILE__
)
here
=
File
.
expand_path
(
File
.
dirname
__FILE__
)
$
:
<<
"
#{
here
}
/../lib"
$
LOAD_PATH
<<
"
#{
here
}
/../lib"
require
'optparse'
require
'optparse'
require
'annotate'
require
'annotate'
...
@@ -33,7 +33,7 @@ OptionParser.new do |opts|
...
@@ -33,7 +33,7 @@ OptionParser.new do |opts|
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)'
)
do
|
p
|
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)'
)
do
|
p
|
ENV
[
'position'
]
=
p
ENV
[
'position'
]
=
p
%w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer)
.
each
do
|
key
|
%w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer)
.
each
do
|
key
|
ENV
[
key
]
=
p
unless
(
has_set_position
[
key
])
ENV
[
key
]
=
p
unless
has_set_position
[
key
]
end
end
end
end
...
@@ -192,10 +192,11 @@ OptionParser.new do |opts|
...
@@ -192,10 +192,11 @@ OptionParser.new do |opts|
opts
.
on
(
'--ignore-unknown-models'
,
"don't display warnings for bad model files"
)
do
|
values
|
opts
.
on
(
'--ignore-unknown-models'
,
"don't display warnings for bad model files"
)
do
|
values
|
ENV
[
'ignore_unknown_models'
]
=
'true'
ENV
[
'ignore_unknown_models'
]
=
'true'
end
end
end
.
parse!
end
.
parse!
options
=
Annotate
.
setup_options
({
is_rake:
ENV
[
'is_rake'
]
&&
!
ENV
[
'is_rake'
].
empty?
})
options
=
Annotate
.
setup_options
(
is_rake:
ENV
[
'is_rake'
]
&&
!
ENV
[
'is_rake'
].
empty?
)
Annotate
.
eager_load
(
options
)
Annotate
.
eager_load
(
options
)
AnnotateModels
.
send
(
target_action
,
options
)
if
Annotate
.
include_models?
AnnotateModels
.
send
(
target_action
,
options
)
if
Annotate
.
include_models?
...
...
This diff is collapsed.
Click to expand it.
lib/annotate.rb
View file @
e1f6eafd
...
@@ -9,7 +9,7 @@ begin
...
@@ -9,7 +9,7 @@ begin
# ActiveSupport 3.x...
# ActiveSupport 3.x...
require
'active_support/hash_with_indifferent_access'
require
'active_support/hash_with_indifferent_access'
require
'active_support/core_ext/object/blank'
require
'active_support/core_ext/object/blank'
rescue
Exception
rescue
StandardError
# ActiveSupport 2.x...
# ActiveSupport 2.x...
require
'active_support/core_ext/hash/indifferent_access'
require
'active_support/core_ext/hash/indifferent_access'
require
'active_support/core_ext/blank'
require
'active_support/core_ext/blank'
...
@@ -35,13 +35,18 @@ module Annotate
...
@@ -35,13 +35,18 @@ module Annotate
:exclude_sti_subclasses
,
:ignore_unknown_models
:exclude_sti_subclasses
,
:ignore_unknown_models
].
freeze
].
freeze
OTHER_OPTIONS
=
[
OTHER_OPTIONS
=
[
:ignore_columns
,
:skip_on_db_migrate
,
:wrapper_open
,
:wrapper_close
,
:wrapper
,
:routes
,
:ignore_columns
,
:skip_on_db_migrate
,
:wrapper_open
,
:wrapper_close
,
:hide_limit_column_types
,
:hide_default_column_types
,
:ignore_routes
,
:active_admin
:wrapper
,
:routes
,
:hide_limit_column_types
,
:hide_default_column_types
,
:ignore_routes
,
:active_admin
].
freeze
].
freeze
PATH_OPTIONS
=
[
PATH_OPTIONS
=
[
:require
,
:model_dir
,
:root_dir
:require
,
:model_dir
,
:root_dir
].
freeze
].
freeze
def
self
.
all_options
[
POSITION_OPTIONS
,
FLAG_OPTIONS
,
PATH_OPTIONS
,
OTHER_OPTIONS
]
end
##
##
# Set default values that can be overridden via environment variables.
# Set default values that can be overridden via environment variables.
#
#
...
@@ -51,7 +56,7 @@ module Annotate
...
@@ -51,7 +56,7 @@ module Annotate
options
=
HashWithIndifferentAccess
.
new
(
options
)
options
=
HashWithIndifferentAccess
.
new
(
options
)
[
POSITION_OPTIONS
,
FLAG_OPTIONS
,
PATH_OPTIONS
,
OTHER_OPTIONS
]
.
flatten
.
each
do
|
key
|
all_options
.
flatten
.
each
do
|
key
|
if
options
.
key?
(
key
)
if
options
.
key?
(
key
)
default_value
=
if
options
[
key
].
is_a?
(
Array
)
default_value
=
if
options
[
key
].
is_a?
(
Array
)
options
[
key
].
join
(
','
)
options
[
key
].
join
(
','
)
...
@@ -97,9 +102,7 @@ module Annotate
...
@@ -97,9 +102,7 @@ module Annotate
end
end
def
self
.
reset_options
def
self
.
reset_options
[
POSITION_OPTIONS
,
FLAG_OPTIONS
,
PATH_OPTIONS
,
OTHER_OPTIONS
].
flatten
.
each
do
|
key
|
all_options
.
flatten
.
each
{
|
key
|
ENV
[
key
.
to_s
]
=
nil
}
ENV
[
key
.
to_s
]
=
nil
end
end
end
def
self
.
skip_on_migration?
def
self
.
skip_on_migration?
...
@@ -126,11 +129,14 @@ module Annotate
...
@@ -126,11 +129,14 @@ module Annotate
return
if
loaded_tasks
return
if
loaded_tasks
self
.
loaded_tasks
=
true
self
.
loaded_tasks
=
true
Dir
[
File
.
join
(
File
.
dirname
(
__FILE__
),
'tasks'
,
'**/*.rake'
)].
each
{
|
rake
|
load
rake
}
Dir
[
File
.
join
(
File
.
dirname
(
__FILE__
),
'tasks'
,
'**/*.rake'
)].
each
do
|
rake
|
load
rake
end
end
end
def
self
.
load_requires
(
options
)
def
self
.
load_requires
(
options
)
options
[
:require
].
each
{
|
path
|
require
path
}
if
options
[
:require
].
count
>
0
options
[
:require
].
count
>
0
&&
options
[
:require
].
each
{
|
path
|
require
path
}
end
end
def
self
.
eager_load
(
options
)
def
self
.
eager_load
(
options
)
...
@@ -161,7 +167,7 @@ module Annotate
...
@@ -161,7 +167,7 @@ module Annotate
def
self
.
bootstrap_rake
def
self
.
bootstrap_rake
begin
begin
require
'rake/dsl_definition'
require
'rake/dsl_definition'
rescue
Exception
=>
e
rescue
StandardError
=>
e
# We might just be on an old version of Rake...
# We might just be on an old version of Rake...
puts
e
.
message
puts
e
.
message
exit
e
.
status_code
exit
e
.
status_code
...
...
This diff is collapsed.
Click to expand it.
spec/annotate/annotate_models_spec.rb
View file @
e1f6eafd
This diff is collapsed.
Click to expand it.
spec/integration/common_validation.rb
View file @
e1f6eafd
...
@@ -2,10 +2,7 @@ module Annotate
...
@@ -2,10 +2,7 @@ module Annotate
module
Validations
module
Validations
module
Common
module
Common
def
self
.
test_commands
def
self
.
test_commands
return
%q{
'bin/annotate && bin/annotate --routes'
bin/annotate &&
bin/annotate --routes
}
end
end
def
self
.
verify_output
(
output
)
def
self
.
verify_output
(
output
)
...
@@ -13,49 +10,47 @@ module Annotate
...
@@ -13,49 +10,47 @@ module Annotate
output
.
should
=~
/Route file annotated./
output
.
should
=~
/Route file annotated./
end
end
def
self
.
verify_files
(
which_files
,
test_rig
,
schema_annotation
,
routes_annotation
,
place_before
=
true
)
def
self
.
verify_files
(
which_files
,
test_rig
,
schema_annotation
,
routes_annotation
,
place_before
=
true
)
check_task_model
(
test_rig
,
schema_annotation
,
place_before
)
if
(
which_files
[
:model
])
check_task_model
(
test_rig
,
schema_annotation
,
place_before
)
if
which_files
[
:model
]
check_task_unittest
(
test_rig
,
schema_annotation
,
place_before
)
if
(
which_files
[
:test
])
check_task_unittest
(
test_rig
,
schema_annotation
,
place_before
)
if
which_files
[
:test
]
check_task_fixture
(
test_rig
,
schema_annotation
,
place_before
)
if
(
which_files
[
:fixture
])
check_task_fixture
(
test_rig
,
schema_annotation
,
place_before
)
if
which_files
[
:fixture
]
check_task_factory
(
test_rig
,
schema_annotation
,
place_before
)
if
(
which_files
[
:factory
])
check_task_factory
(
test_rig
,
schema_annotation
,
place_before
)
if
which_files
[
:factory
]
check_routes
(
test_rig
,
routes_annotation
,
place_before
)
if
(
which_files
[
:routes
])
check_routes
(
test_rig
,
routes_annotation
,
place_before
)
if
which_files
[
:routes
]
end
end
def
self
.
check_task_model
(
test_rig
,
annotation
,
place_before
=
true
)
def
self
.
check_task_model
(
test_rig
,
annotation
,
place_before
=
true
)
model
=
apply_annotation
(
test_rig
,
"app/models/task.rb"
,
annotation
,
place_before
)
model
=
apply_annotation
(
test_rig
,
'app/models/task.rb'
,
annotation
,
place_before
)
File
.
read
(
"app/models/task.rb"
).
should
==
model
File
.
read
(
'app/models/task.rb'
).
should
==
model
end
end
def
self
.
check_routes
(
test_rig
,
annotation
,
place_before
=
true
)
def
self
.
check_routes
(
test_rig
,
annotation
,
place_before
=
true
)
routes
=
apply_annotation
(
test_rig
,
"config/routes.rb"
,
annotation
,
place_before
)
routes
=
apply_annotation
(
test_rig
,
'config/routes.rb'
,
annotation
,
place_before
)
File
.
read
(
"config/routes.rb"
).
File
.
read
(
'config/routes.rb'
)
sub
(
/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/
,
'YYYY-MM-DD HH:MM'
).
.
sub
(
/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/
,
'YYYY-MM-DD HH:MM'
)
should
==
routes
.
should
==
routes
end
end
def
self
.
check_task_unittest
(
test_rig
,
annotation
,
place_before
=
true
)
def
self
.
check_task_unittest
(
test_rig
,
annotation
,
place_before
=
true
)
unittest
=
apply_annotation
(
test_rig
,
"test/unit/task_test.rb"
,
annotation
,
place_before
)
unittest
=
apply_annotation
(
test_rig
,
'test/unit/task_test.rb'
,
annotation
,
place_before
)
File
.
read
(
"test/unit/task_test.rb"
).
should
==
unittest
File
.
read
(
'test/unit/task_test.rb'
).
should
==
unittest
end
end
def
self
.
check_task_modeltest
(
test_rig
,
annotation
,
place_before
=
true
)
def
self
.
check_task_modeltest
(
test_rig
,
annotation
,
place_before
=
true
)
unittest
=
apply_annotation
(
test_rig
,
"test/models/task_test.rb"
,
annotation
,
place_before
)
unittest
=
apply_annotation
(
test_rig
,
'test/models/task_test.rb'
,
annotation
,
place_before
)
File
.
read
(
"test/models/task_test.rb"
).
should
==
unittest
File
.
read
(
'test/models/task_test.rb'
).
should
==
unittest
end
end
def
self
.
check_task_factory
(
test_rig
,
annotation
,
place_before
=
true
)
def
self
.
check_task_factory
(
test_rig
,
annotation
,
place_before
=
true
)
fixture
=
apply_annotation
(
test_rig
,
"test/factories/tasks.rb"
,
annotation
,
place_before
)
fixture
=
apply_annotation
(
test_rig
,
'test/factories/tasks.rb'
,
annotation
,
place_before
)
File
.
read
(
"test/factories/tasks.rb"
).
should
==
fixture
File
.
read
(
'test/factories/tasks.rb'
).
should
==
fixture
end
end
def
self
.
check_task_fixture
(
test_rig
,
annotation
,
place_before
=
true
)
def
self
.
check_task_fixture
(
test_rig
,
annotation
,
place_before
=
true
)
fixture
=
apply_annotation
(
test_rig
,
"test/fixtures/tasks.yml"
,
annotation
,
place_before
)
fixture
=
apply_annotation
(
test_rig
,
'test/fixtures/tasks.yml'
,
annotation
,
place_before
)
File
.
read
(
"test/fixtures/tasks.yml"
).
should
==
fixture
File
.
read
(
'test/fixtures/tasks.yml'
).
should
==
fixture
end
end
protected
def
self
.
apply_annotation
(
test_rig
,
fname
,
annotation
,
place_before
=
true
)
def
self
.
apply_annotation
(
test_rig
,
fname
,
annotation
,
place_before
=
true
)
corpus
=
File
.
read
(
File
.
join
(
test_rig
,
fname
))
corpus
=
File
.
read
(
File
.
join
(
test_rig
,
fname
))
if
place_before
if
place_before
annotation
+
"
\n
"
+
corpus
annotation
+
"
\n
"
+
corpus
...
...
This diff is collapsed.
Click to expand it.
spec/integration/integration_spec.rb
View file @
e1f6eafd
...
@@ -17,12 +17,13 @@ ENV['BUNDLE_GEMFILE'] = './Gemfile'
...
@@ -17,12 +17,13 @@ ENV['BUNDLE_GEMFILE'] = './Gemfile'
describe
"annotate inside Rails, using
#{
CURRENT_RUBY
}
"
do
describe
"annotate inside Rails, using
#{
CURRENT_RUBY
}
"
do
chosen_scenario
=
nil
chosen_scenario
=
nil
if
!
ENV
[
'SCENARIO'
].
blank?
unless
ENV
[
'SCENARIO'
].
blank?
chosen_scenario
=
File
.
expand_path
(
ENV
[
'SCENARIO'
])
chosen_scenario
=
File
.
expand_path
(
ENV
[
'SCENARIO'
])
raise
"Can't find specified scenario '
#{
chosen_scenario
}
'!"
unless
(
File
.
directory?
(
chosen_scenario
)
)
raise
"Can't find specified scenario '
#{
chosen_scenario
}
'!"
unless
File
.
directory?
(
chosen_scenario
)
end
end
Annotate
::
Integration
::
SCENARIOS
.
each
do
|
test_rig
,
base_dir
,
test_name
|
Annotate
::
Integration
::
SCENARIOS
.
each
do
|
test_rig
,
base_dir
,
test_name
|
next
if
(
chosen_scenario
&&
chosen_scenario
!=
test_rig
)
next
if
chosen_scenario
&&
chosen_scenario
!=
test_rig
it
"works under
#{
test_name
}
"
do
it
"works under
#{
test_name
}
"
do
unless
USING_RVM
unless
USING_RVM
skip
'Must have RVM installed.'
skip
'Must have RVM installed.'
...
@@ -51,7 +52,7 @@ describe "annotate inside Rails, using #{CURRENT_RUBY}" do
...
@@ -51,7 +52,7 @@ describe "annotate inside Rails, using #{CURRENT_RUBY}" do
# By default, rvm_ruby_string isn't inherited over properly, so let's
# By default, rvm_ruby_string isn't inherited over properly, so let's
# make sure it's there so our .rvmrc will work.
# make sure it's there so our .rvmrc will work.
ENV
[
'rvm_ruby_string'
]
=
CURRENT_RUBY
ENV
[
'rvm_ruby_string'
]
=
CURRENT_RUBY
require
base_dir
.
to_s
# Will get "#{base_dir}.rb"...
require
base_dir
.
to_s
# Will get "#{base_dir}.rb"...
klass
=
"Annotate::Validations::
#{
base_dir
.
tr
(
'.'
,
'_'
).
classify
}
"
.
constantize
klass
=
"Annotate::Validations::
#{
base_dir
.
tr
(
'.'
,
'_'
).
classify
}
"
.
constantize
...
...
This diff is collapsed.
Click to expand it.
spec/integration/rails_3.2.8.rb
View file @
e1f6eafd
...
@@ -4,7 +4,7 @@ module Annotate
...
@@ -4,7 +4,7 @@ module Annotate
module
Validations
module
Validations
class
Rails328
<
Base
class
Rails328
<
Base
def
self
.
schema_annotation
def
self
.
schema_annotation
return
<<-
RUBY
<<-
RUBY
# == Schema Information
# == Schema Information
#
#
# Table name: tasks
# Table name: tasks
...
@@ -18,7 +18,7 @@ RUBY
...
@@ -18,7 +18,7 @@ RUBY
end
end
def
self
.
route_annotation
def
self
.
route_annotation
return
<<-
RUBY
<<-
RUBY
# == Route Map (Updated YYYY-MM-DD HH:MM)
# == Route Map (Updated YYYY-MM-DD HH:MM)
#
#
# tasks GET /tasks(.:format) tasks#index
# tasks GET /tasks(.:format) tasks#index
...
...
This diff is collapsed.
Click to expand it.
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