rails_best_practices 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,5 +8,6 @@ require 'rails_best_practices/core/visitable_sexp'
8
8
  require 'rails_best_practices/core/models'
9
9
  require 'rails_best_practices/core/model_associations'
10
10
  require 'rails_best_practices/core/model_attributes'
11
+ require 'rails_best_practices/core/mailers'
11
12
 
12
13
  require 'rails_best_practices/core_ext/enumerable'
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ module RailsBestPractices
3
+ module Core
4
+ class Mailers < Array
5
+ end
6
+ end
7
+ end
@@ -6,14 +6,22 @@ require 'rails_best_practices/prepares/schema_prepare'
6
6
  module RailsBestPractices
7
7
  module Prepares
8
8
  class <<self
9
- attr_writer :models, :model_associations, :model_attributes, :mailer_names
9
+ attr_writer :models, :model_associations, :model_attributes, :mailers
10
10
 
11
- [:models, :model_associations, :model_attributes, :mailer_names].each do |method_name|
12
- class_eval <<-EOS
13
- def #{method_name}
14
- @#{method_name} ||= []
15
- end
16
- EOS
11
+ def models
12
+ @models ||= Core::Models.new
13
+ end
14
+
15
+ def model_associations
16
+ @model_associations ||= Core::ModelAssociations.new
17
+ end
18
+
19
+ def model_attributes
20
+ @model_attributes ||= Core::ModelAttributes.new
21
+ end
22
+
23
+ def mailers
24
+ @mailers ||= Core::Mailers.new
17
25
  end
18
26
  end
19
27
  end
@@ -15,7 +15,7 @@ module RailsBestPractices
15
15
  end
16
16
 
17
17
  def initialize
18
- @mailer_names = []
18
+ @mailers = Core::Mailers.new
19
19
  end
20
20
 
21
21
  # check class node.
@@ -24,8 +24,8 @@ module RailsBestPractices
24
24
  # then remember its class name.
25
25
  def start_class(class_node)
26
26
  if s(:colon2, s(:const, :ActionMailer), :Base) == class_node.base_class
27
- @mailer_names << class_node.class_name
28
- Prepares.mailer_names = @mailer_names
27
+ @mailers << class_node.class_name.to_s
28
+ Prepares.mailers = @mailers
29
29
  end
30
30
  end
31
31
  end
@@ -112,15 +112,15 @@ module RailsBestPractices
112
112
  def deliver_mailer?(node)
113
113
  node.grep_nodes(:node_type => :call) do |child_node|
114
114
  # rails2 actionmailer deliver
115
- return true if child_node.message.to_s =~ /^deliver_/ && mailer_names.include?(child_node.subject.to_s)
115
+ return true if child_node.message.to_s =~ /^deliver_/ && mailers.include?(child_node.subject.to_s)
116
116
  # rails3 actionmailer deliver
117
- return true if :deliver == child_node.message && mailer_names.include?(child_node.subject.subject.to_s)
117
+ return true if :deliver == child_node.message && mailers.include?(child_node.subject.subject.to_s)
118
118
  end
119
119
  false
120
120
  end
121
121
 
122
- def mailer_names
123
- @mailer_names ||= Prepares.mailer_names.collect(&:to_s)
122
+ def mailers
123
+ @mailers ||= Prepares.mailers
124
124
  end
125
125
  end
126
126
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "0.8.0"
3
+ VERSION = "0.8.1"
4
4
  end
5
5
 
@@ -9,6 +9,6 @@ describe RailsBestPractices::Prepares::MailerPrepare do
9
9
  end
10
10
  EOF
11
11
  runner.prepare('app/mailers/project_mailer.rb', content)
12
- RailsBestPractices::Prepares.mailer_names.should == [:ProjectMailer]
12
+ RailsBestPractices::Prepares.mailers.should == ["ProjectMailer"]
13
13
  end
14
14
  end
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: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Huang
@@ -216,6 +216,7 @@ files:
216
216
  - lib/rails_best_practices/core/check.rb
217
217
  - lib/rails_best_practices/core/checking_visitor.rb
218
218
  - lib/rails_best_practices/core/error.rb
219
+ - lib/rails_best_practices/core/mailers.rb
219
220
  - lib/rails_best_practices/core/model_associations.rb
220
221
  - lib/rails_best_practices/core/model_attributes.rb
221
222
  - lib/rails_best_practices/core/models.rb