Class: AutoError::HelperContext
- Inherits:
-
Object
- Object
- AutoError::HelperContext
- Defined in:
- lib/auto_error/helper_context.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
Instance Method Summary collapse
- #default_url_options ⇒ Object
-
#initialize(env) ⇒ HelperContext
constructor
A new instance of HelperContext.
Constructor Details
#initialize(env) ⇒ HelperContext
Returns a new instance of HelperContext.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/auto_error/helper_context.rb', line 5 def initialize( env ) @env = env AutoError::Config.helpers.each do |mod_name| # grab the module by name we were given # it is available in the 'parent' Rails.application mod = Rails.application.class.qualified_const_get(mod_name) class_eval do # include that module in this HelperContext send( :include, mod ) # but go through all of its instance methods # and alias-method-chain style twiddle them so we can bind # them to the correct environment inside auto_error mod.instance_methods.each do |imeth| alias :"#{imeth}_without_env" :"#{imeth}" send( :define_method, :"#{imeth}" ) do |*args| env.instance_exec( *args, &method( :"#{imeth}_without_env" ) ) end end # also include rails helpers and ActionView helpers send( :include, ActionView::Helpers ) send( :include, Rails.application.routes.url_helpers ) end end end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
3 4 5 |
# File 'lib/auto_error/helper_context.rb', line 3 def env @env end |
Instance Method Details
#default_url_options ⇒ Object
34 |
# File 'lib/auto_error/helper_context.rb', line 34 def ; {}; end |