tanga_namespaced_helpers 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module TangaNamespacedHelpers
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,6 +5,9 @@ require "tanga_namespaced_helpers/version"
5
5
  module TangaNamespacedHelpers
6
6
  def self.reset! controller
7
7
  @view = controller.view_context
8
+ if controller.is_a?(ActionController::Base)
9
+ @controller = controller
10
+ end
8
11
 
9
12
  # Hack to get Haml helpers available
10
13
  if defined? Haml
@@ -19,13 +22,34 @@ module TangaNamespacedHelpers
19
22
  @view
20
23
  end
21
24
 
25
+ def self.controller
26
+ @controller
27
+ end
28
+
22
29
  # TODO Gotta be a better way to do this.
23
30
  def view
24
31
  TangaNamespacedHelpers.view
25
32
  end
26
33
 
34
+ def controller
35
+ TangaNamespacedHelpers.controller
36
+ end
37
+
27
38
  def method_missing *args, &block
39
+ retry_count ||= 0
28
40
  view.send *args, &block
41
+ rescue NoMethodError
42
+ # This is pretty stupid. ActionMailer sometimes resets the current view context.
43
+ # So, if there's a NoMethodError (i.e. access the session after ActionMailer
44
+ # resets the context), we need to reset it to the original controller
45
+ # for the request and try one more time.
46
+ if retry_count == 0
47
+ TangaNamespacedHelpers.reset!(controller)
48
+ retry_count += 1
49
+ retry
50
+ else
51
+ raise
52
+ end
29
53
  end
30
54
 
31
55
  module ControllerMethods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanga_namespaced_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-03-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Namespace your Rails helper methods
15
15
  email: