rails_best_practices 0.5.6 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/README.md +161 -0
  2. data/lib/rails_best_practices.rb +158 -20
  3. data/lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb +108 -34
  4. data/lib/rails_best_practices/checks/always_add_db_index_check.rb +148 -29
  5. data/lib/rails_best_practices/checks/check.rb +178 -75
  6. data/lib/rails_best_practices/checks/dry_bundler_in_capistrano_check.rb +26 -5
  7. data/lib/rails_best_practices/checks/isolate_seed_data_check.rb +66 -15
  8. data/lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb +53 -12
  9. data/lib/rails_best_practices/checks/law_of_demeter_check.rb +59 -30
  10. data/lib/rails_best_practices/checks/move_code_into_controller_check.rb +35 -15
  11. data/lib/rails_best_practices/checks/move_code_into_helper_check.rb +56 -12
  12. data/lib/rails_best_practices/checks/move_code_into_model_check.rb +30 -32
  13. data/lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb +45 -15
  14. data/lib/rails_best_practices/checks/move_model_logic_into_model_check.rb +31 -27
  15. data/lib/rails_best_practices/checks/needless_deep_nesting_check.rb +99 -38
  16. data/lib/rails_best_practices/checks/not_use_default_route_check.rb +43 -12
  17. data/lib/rails_best_practices/checks/overuse_route_customizations_check.rb +140 -28
  18. data/lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb +44 -30
  19. data/lib/rails_best_practices/checks/replace_instance_variable_with_local_variable_check.rb +18 -7
  20. data/lib/rails_best_practices/checks/use_before_filter_check.rb +88 -18
  21. data/lib/rails_best_practices/checks/use_model_association_check.rb +61 -22
  22. data/lib/rails_best_practices/checks/use_observer_check.rb +125 -23
  23. data/lib/rails_best_practices/checks/use_query_attribute_check.rb +75 -47
  24. data/lib/rails_best_practices/checks/use_say_with_time_in_migrations_check.rb +59 -10
  25. data/lib/rails_best_practices/checks/use_scope_access_check.rb +78 -23
  26. data/lib/rails_best_practices/command.rb +19 -34
  27. data/lib/rails_best_practices/core.rb +4 -2
  28. data/lib/rails_best_practices/core/checking_visitor.rb +49 -19
  29. data/lib/rails_best_practices/core/error.rb +5 -2
  30. data/lib/rails_best_practices/core/runner.rb +79 -55
  31. data/lib/rails_best_practices/core/visitable_sexp.rb +325 -55
  32. data/lib/rails_best_practices/{core/core_ext.rb → core_ext/enumerable.rb} +3 -6
  33. data/lib/rails_best_practices/core_ext/nil_class.rb +8 -0
  34. data/lib/rails_best_practices/version.rb +1 -1
  35. data/rails_best_practices.yml +2 -2
  36. metadata +8 -7
  37. data/README.textile +0 -150
@@ -1,12 +1,9 @@
1
1
  # encoding: utf-8
2
2
  module Enumerable
3
+ # Get the duplicate entries from an Enumerable.
4
+ #
5
+ # @return [Enumerable] the duplicate entries.
3
6
  def dups
4
7
  inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
5
8
  end
6
9
  end
7
-
8
- class NilClass
9
- def method_missing(method_sym, *arguments, &block)
10
- return nil
11
- end
12
- end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ class NilClass
3
+ # do not raise error when calling messages on nil object.
4
+ def method_missing(method_sym, *arguments, &block)
5
+ return nil
6
+ end
7
+ end
8
+
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "0.5.6"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
 
@@ -3,7 +3,7 @@ UseModelAssociationCheck: { }
3
3
  UseScopeAccessCheck: { }
4
4
  AddModelVirtualAttributeCheck: { }
5
5
  ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
6
- MoveModelLogicIntoModelCheck: { called_count: 4 }
6
+ MoveModelLogicIntoModelCheck: { use_count: 4 }
7
7
  OveruseRouteCustomizationsCheck: { customize_count: 3 }
8
8
  NeedlessDeepNestingCheck: { nested_count: 2 }
9
9
  NotUseDefaultRouteCheck: { }
@@ -14,7 +14,7 @@ IsolateSeedDataCheck: { }
14
14
  AlwaysAddDbIndexCheck: { }
15
15
  UseBeforeFilterCheck: { }
16
16
  MoveCodeIntoControllerCheck: { }
17
- MoveCodeIntoModelCheck: { }
17
+ MoveCodeIntoModelCheck: { use_count: 2 }
18
18
  MoveCodeIntoHelperCheck: { array_count: 3 }
19
19
  ReplaceInstanceVariableWithLocalVariableCheck: { }
20
20
  DryBundlerInCapistranoCheck: { }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
8
  - 6
10
- version: 0.5.6
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Huang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-15 00:00:00 +08:00
18
+ date: 2010-12-24 00:00:00 +08:00
19
19
  default_executable: rails_best_practices
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -165,7 +165,7 @@ extensions: []
165
165
 
166
166
  extra_rdoc_files:
167
167
  - MIT_LICENSE
168
- - README.textile
168
+ - README.md
169
169
  files:
170
170
  - lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb
171
171
  - lib/rails_best_practices/checks/always_add_db_index_check.rb
@@ -193,16 +193,17 @@ files:
193
193
  - lib/rails_best_practices/checks.rb
194
194
  - lib/rails_best_practices/command.rb
195
195
  - lib/rails_best_practices/core/checking_visitor.rb
196
- - lib/rails_best_practices/core/core_ext.rb
197
196
  - lib/rails_best_practices/core/error.rb
198
197
  - lib/rails_best_practices/core/runner.rb
199
198
  - lib/rails_best_practices/core/visitable_sexp.rb
200
199
  - lib/rails_best_practices/core.rb
200
+ - lib/rails_best_practices/core_ext/enumerable.rb
201
+ - lib/rails_best_practices/core_ext/nil_class.rb
201
202
  - lib/rails_best_practices/version.rb
202
203
  - lib/rails_best_practices.rb
203
204
  - rails_best_practices.yml
204
205
  - MIT_LICENSE
205
- - README.textile
206
+ - README.md
206
207
  - bin/rails_best_practices
207
208
  has_rdoc: true
208
209
  homepage: http://rails-bestpractices.com
data/README.textile DELETED
@@ -1,150 +0,0 @@
1
- h1. rails_best_practices
2
-
3
- rails_best_practices is a code metric tool to check the quality of rails codes.
4
-
5
- *************************************************
6
-
7
- h2. Usage
8
-
9
- At the root directory of rails app
10
-
11
- <pre><code>
12
- rails_best_practices .
13
- </code></pre>
14
-
15
- notice the period at the end, it can be the relative or absolute path of your rails app.
16
-
17
- And default rails_best_practices will do parse codes in vendor, spec, test and features directories. If you need, see the command options:
18
-
19
- <pre><code>
20
- $ rails_best_practices -h
21
- Usage: rails_best_practices [options]
22
- -d, --debug Debug mode
23
- --vendor include vendor files
24
- --spec include spec files
25
- --test include test files
26
- --features include features files
27
- -x, --exclude PATTERNS Don't analyze files matching a pattern
28
- (comma-separated regexp list)
29
- -v, --version Show this version
30
- -h, --help Show this message
31
- </code></pre>
32
-
33
- *************************************************
34
-
35
- h2. Resources
36
-
37
- Homepage: "http://rails-bestpractices.com":http://rails-bestpractices.com
38
- Repository: "http://github.com/flyerhzm/rails_best_practices":http://github.com/flyerhzm/rails_best_practices
39
- Wiki: "http://github.com/flyerhzm/rails_best_practices/wiki":http://github.com/flyerhzm/rails_best_practices/wiki
40
-
41
- *************************************************
42
-
43
- h2. Install
44
-
45
- <pre><code>
46
- gem install rails_best_practices
47
- </code></pre>
48
-
49
- *************************************************
50
-
51
- h2. Issue
52
-
53
- If you got NoMethodError or any syntax error, you should use debug mode to detect which file rails_best_practices is parsing and getting the error.
54
-
55
- <pre><code>
56
- rails_best_practices -d .
57
- </code></pre>
58
-
59
- Then give me the error stack and the source code of the file that rails_best_practices is parsing error.
60
-
61
- "http://github.com/flyerhzm/rails_best_practices/issues":http://github.com/flyerhzm/rails_best_practices/issues
62
-
63
- *************************************************
64
-
65
- h2. Customize Configuration
66
-
67
- Copy <code>rails_best_practices.yml</code> in the root directory of rails_best_practices gem to <code>config</code> directory
68
- Now you can customize the configuration, the default configuration is as follows:
69
-
70
- <pre><code>
71
- MoveFinderToNamedScopeCheck: { }
72
- UseModelAssociationCheck: { }
73
- UseScopeAccessCheck: { }
74
- AddModelVirtualAttributeCheck: { }
75
- ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
76
- MoveModelLogicIntoModelCheck: { called_count: 4 }
77
- OveruseRouteCustomizationsCheck: { customize_count: 3 }
78
- NeedlessDeepNestingCheck: { nested_count: 2 }
79
- NotUseDefaultRouteCheck: { }
80
- KeepFindersOnTheirOwnModelCheck: { }
81
- LawOfDemeterCheck: { }
82
- UseObserverCheck: { }
83
- IsolateSeedDataCheck: { }
84
- AlwaysAddDbIndexCheck: { }
85
- UseBeforeFilterCheck: { }
86
- MoveCodeIntoControllerCheck: { }
87
- MoveCodeIntoModelCheck: { }
88
- MoveCodeIntoHelperCheck: { array_count: 3 }
89
- ReplaceInstanceVariableWithLocalVariableCheck: { }
90
- DryBundlerInCapistranoCheck: { }
91
- UseSayWithTimeInMigrationsCheck: { }
92
- UseQueryAttributeCheck: { }
93
- </code></pre>
94
-
95
- *************************************************
96
-
97
- h2. Implementation
98
-
99
- * Move code from Controller to Model
100
- ## Move finder to named_scope (rails2 only)
101
- ## Use model association
102
- ## Use scope access
103
- ## Add model virtual attribute
104
- ## Replace Complex Creation with Factory Method
105
- ## Move Model Logic into the Model
106
-
107
- * RESTful Conventions
108
- ## Overuse route customizations
109
- ## Needless deep nesting
110
- ## Not use default route
111
-
112
- * Model
113
- ## Keep Finders on Their Own Model (rails2 only)
114
- ## the Law of Demeter
115
- ## Use Observer
116
- ## Use Query Attribute
117
-
118
- * Migration
119
- ## Isolating Seed Data
120
- ## Always add DB index
121
- ## Use Say with Time in Migrations
122
-
123
- * Controller
124
- ## Use before_filter
125
-
126
- * View
127
- ## Move code into controller
128
- ## Move code into model
129
- ## Move code into helper
130
- ## Replace instance variable with local variable
131
-
132
- * Deployment
133
- ## Dry bundler in capistrano
134
-
135
- *************************************************
136
-
137
- h2. Contribute
138
-
139
- If you want to add your rails best practices into the gem, please post your best practices on "http://rails-bestpractices.com":http://rails-bestpractices.com
140
-
141
- *************************************************
142
-
143
- h2. Contact
144
-
145
- Follow us on twitter: "http://twitter.com/railsbp":http://twitter.com/railsbp
146
- Send us email: "team@rails-bestpractices.com":mailto:team@rails-bestpractices.com
147
-
148
- *************************************************
149
-
150
- Copyright © 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license