rails_best_practices 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -30,6 +30,19 @@ rails_best_practices .
30
30
 
31
31
  notice the period at the end, it can be the relative or absolute path of your rails app.
32
32
 
33
+ And default rails_best_practices will do parse codes in vendor, spec, test and stories directories. If you need, see the command options:
34
+
35
+ <pre><code>
36
+ $ rails_best_practices -h
37
+ Usage: rails_best_practices [options]
38
+ -d, --debug Debug mode
39
+ --vendor include vendor files
40
+ --spec include spec files
41
+ --test include test files
42
+ --stories include stories files
43
+ -h, --help Show this message
44
+ </code></pre>
45
+
33
46
  *************************************************
34
47
 
35
48
  h2. Customize Configuration
@@ -97,7 +110,7 @@ h2. Progress
97
110
 
98
111
  * Lesson 5. Controller
99
112
  ## [-Use before_filter-]
100
- ## DRY Controller
113
+ ## [-DRY Controller-] # not implement, use http://github.com/josevalim/inherited_resources
101
114
 
102
115
  * Lesson 6. View
103
116
  ## [-Move code into controller-]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -8,8 +8,8 @@ module RailsBestPractices
8
8
  CONTROLLER_FILES = /_controller.rb$/
9
9
  MIGRATION_FILES = /db\/migrate\/.*rb/
10
10
  MODLE_FILES = /models\/.*rb/
11
- VIEW_FILES = /views\/.*erb/
12
- PARTIAL_VIEW_FILES = /views\/.*\/_.*erb/
11
+ VIEW_FILES = /views\/.*(erb|haml)/
12
+ PARTIAL_VIEW_FILES = /views\/.*\/_.*(erb|haml)/
13
13
 
14
14
  def initialize
15
15
  @errors = []
@@ -20,4 +20,4 @@ module RailsBestPractices
20
20
  end
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -1,7 +1,7 @@
1
1
  require 'optparse'
2
2
 
3
3
  def expand_dirs_to_files *dirs
4
- extensions = ['rb', 'erb', 'builder']
4
+ extensions = ['rb', 'erb', 'haml', 'builder']
5
5
 
6
6
  dirs.flatten.map { |p|
7
7
  if File.directory? p
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'ruby_parser'
3
3
  require 'erb'
4
+ require 'haml'
4
5
  require 'yaml'
5
6
 
6
7
  module RailsBestPractices
@@ -29,6 +30,9 @@ module RailsBestPractices
29
30
  if filename =~ /.*erb/
30
31
  content = ERB.new(content).src
31
32
  end
33
+ if filename =~ /.*haml/
34
+ content = Haml::Engine.new(content).precompiled
35
+ end
32
36
  node = parse(filename, content)
33
37
  node.accept(@checker) if node
34
38
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_best_practices}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Huang"]
12
- s.date = %q{2009-11-10}
12
+ s.date = %q{2009-11-13}
13
13
  s.default_executable = %q{rails_best_practices}
14
14
  s.description = %q{check rails files according to ihower's presentation 'rails best practices'}
15
15
  s.email = %q{flyerhzm@gmail.com}
@@ -88,27 +88,27 @@ Gem::Specification.new do |s|
88
88
  s.rubygems_version = %q{1.3.5}
89
89
  s.summary = %q{check rails files according to ihower's presentation 'rails best practices'}
90
90
  s.test_files = [
91
- "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
92
- "spec/rails_best_practices/checks/always_add_db_index_check_spec.rb",
93
- "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
94
- "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
95
- "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
96
- "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
97
- "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
98
- "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
99
- "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
91
+ "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
100
92
  "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
101
- "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
102
- "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
103
- "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
93
+ "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
94
+ "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
95
+ "spec/rails_best_practices/checks/use_observer_check_spec.rb",
104
96
  "spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
97
+ "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
98
+ "spec/rails_best_practices/checks/use_filter_check_spec.rb",
99
+ "spec/rails_best_practices/checks/always_add_db_index_check_spec.rb",
100
+ "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
101
+ "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
102
+ "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
105
103
  "spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
104
+ "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
105
+ "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
106
+ "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
107
+ "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
106
108
  "spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb",
107
- "spec/rails_best_practices/checks/use_filter_check_spec.rb",
108
109
  "spec/rails_best_practices/checks/use_model_association_check_spec.rb",
109
- "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
110
- "spec/rails_best_practices/checks/use_observer_check_spec.rb",
111
- "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
110
+ "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
111
+ "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
112
112
  "spec/spec_helper.rb"
113
113
  ]
114
114
 
@@ -24,6 +24,18 @@ describe RailsBestPractices::Checks::LawOfDemeterCheck do
24
24
  errors[0].to_s.should == "app/views/invoices/show.html.erb:1 - law of demeter"
25
25
  end
26
26
 
27
+ it "should law of demeter" do
28
+ content = <<-EOF
29
+ = @invoice.user.name
30
+ = @invoice.user.address
31
+ = @invoice.user.cellphone
32
+ EOF
33
+ @runner.check('app/views/invoices/show.html.haml', content)
34
+ errors = @runner.errors
35
+ errors.should_not be_empty
36
+ errors[0].to_s.should == "app/views/invoices/show.html.haml:1 - law of demeter"
37
+ end
38
+
27
39
  it "should no law of demeter" do
28
40
  content = <<-EOF
29
41
  <%= @invoice.user_name %>
@@ -15,6 +15,16 @@ describe RailsBestPractices::Checks::ReplaceInstanceVariableWithLocalVariableChe
15
15
  errors[0].to_s.should == "app/views/posts/_post.html.erb:1 - replace instance variable with local variable"
16
16
  end
17
17
 
18
+ it "should replace instance variable with local varialbe in haml file" do
19
+ content = <<-EOF
20
+ = @post.title
21
+ EOF
22
+ @runner.check('app/views/posts/_post.html.haml', content)
23
+ errors = @runner.errors
24
+ errors.should_not be_empty
25
+ errors[0].to_s.should == "app/views/posts/_post.html.haml:1 - replace instance variable with local variable"
26
+ end
27
+
18
28
  it "should not replace instance variable with local varialbe" do
19
29
  content = <<-EOF
20
30
  <%= post.title %>
@@ -23,4 +33,4 @@ describe RailsBestPractices::Checks::ReplaceInstanceVariableWithLocalVariableChe
23
33
  errors = @runner.errors
24
34
  errors.should be_empty
25
35
  end
26
- end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-10 00:00:00 +08:00
12
+ date: 2009-11-13 00:00:00 +08:00
13
13
  default_executable: rails_best_practices
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -133,25 +133,25 @@ signing_key:
133
133
  specification_version: 3
134
134
  summary: check rails files according to ihower's presentation 'rails best practices'
135
135
  test_files:
136
- - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
137
- - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
138
136
  - spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb
139
- - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
140
- - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
141
- - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
142
- - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
143
- - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
144
- - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
145
137
  - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
146
- - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
147
- - spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
148
- - spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
138
+ - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
139
+ - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
140
+ - spec/rails_best_practices/checks/use_observer_check_spec.rb
149
141
  - spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
142
+ - spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
143
+ - spec/rails_best_practices/checks/use_filter_check_spec.rb
144
+ - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
145
+ - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
146
+ - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
147
+ - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
150
148
  - spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
149
+ - spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
150
+ - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
151
+ - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
152
+ - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
151
153
  - spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb
152
- - spec/rails_best_practices/checks/use_filter_check_spec.rb
153
154
  - spec/rails_best_practices/checks/use_model_association_check_spec.rb
154
- - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
155
- - spec/rails_best_practices/checks/use_observer_check_spec.rb
156
- - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
155
+ - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
156
+ - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
157
157
  - spec/spec_helper.rb