has_web_fallback 0.1.1 → 0.1.3

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.
@@ -10,23 +10,30 @@ module Leftbrained
10
10
 
11
11
  def self.included(base)
12
12
  base.extend(ClassMethods)
13
- end
14
-
15
-
13
+ end
16
14
  # mattr_accessor :write_web_fallbacks
17
15
 
18
16
  module ClassMethods
19
17
 
20
- def has_web_fallback(name, options={})
18
+ def has_web_fallback?(method_name=nil)
19
+ false
20
+ end
21
+
22
+ def has_web_fallback(name, options={})
23
+ extend Leftbrained::HasWebFallback::IncludedClassMethods
21
24
  write_inheritable_attribute(:methods_with_web_fallback, {}) if methods_with_web_fallback.nil?
22
25
  methods_with_web_fallback[name] = { :keep_for=>7.days }.merge(options)
23
-
26
+
24
27
  class_eval <<-EOV
25
28
  include Leftbrained::HasWebFallback::InstanceMethods
26
29
  EOV
27
30
  end
28
-
29
- def has_web_fallback?(method_name)
31
+ end
32
+
33
+ module IncludedClassMethods
34
+
35
+ def has_web_fallback?(method_name=nil)
36
+ return true if method_name.nil?
30
37
  methods_with_web_fallback.include? method_name.to_sym
31
38
  end
32
39
 
@@ -5,7 +5,7 @@ namespace :has_web_fallback do
5
5
  desc "Remove out of date web_fallback caches for a named action mailer CLASS"
6
6
  task :clean=>[:environment] do |t|
7
7
  klass = ENV['CLASS'].constantize
8
- klass.clear_web_fallback_caches if klass.respond_to? :clear_web_fallback_caches
8
+ klass.clear_web_fallback_caches if klass.has_web_fallback?
9
9
  end
10
10
 
11
11
  desc "Remove out of date web_fallback caches for all ActionMailer classes"
@@ -14,7 +14,10 @@ namespace :has_web_fallback do
14
14
  Dir.glob(File.join(RAILS_ROOT, '**', "*_mailer.rb")) do |file|
15
15
  mailer = File.basename(file, '.rb')
16
16
  klass = mailer.camelize.constantize
17
- klass.clear_web_fallback_caches if klass.respond_to? :clear_web_fallback_caches
17
+ if klass.has_web_fallback?
18
+ puts "Cleaning has_web_fallback caches for #{klass}..."
19
+ klass.clear_web_fallback_caches
20
+ end
18
21
  end
19
22
  end
20
23
 
@@ -45,6 +45,14 @@ class HasWebFallbackTest < ActionMailer::TestCase
45
45
  uuid_2 = ExampleMailer.web_fallback_uuid_for(:welcome)
46
46
  assert uuid_1 != uuid_2, "UUID clash - #{uuid_1} vs #{uuid_2}"
47
47
  end
48
+
49
+ should "not report that ActionMailer::Base uses has_web_fallback" do
50
+ assert !ActionMailer::Base.has_web_fallback?
51
+ end
52
+
53
+ should "respond to has_web_fallback" do
54
+ assert ExampleMailer.has_web_fallback?
55
+ end
48
56
 
49
57
  should_eventually "be able to list cached files for a given function that should be deleted" do
50
58
  # I have quite literally no idea how to test this without
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_web_fallback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Montague