Module: GlobalSession::Rails::ActionControllerInstanceMethods
- Defined in:
- lib/global_session/rails/action_controller_instance_methods.rb
Overview
Module that is mixed into ActionController-derived classes when the class method has_global_session is called.
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#global_session ⇒ Object
Global session reader.
-
#global_session_config ⇒ Object
Shortcut accessor for global session configuration object.
-
#global_session_initialize ⇒ Object
Filter to initialize the global session.
- #global_session_options ⇒ Object
-
#global_session_skip_renew ⇒ Object
Filter to disable auto-renewal of the session.
-
#global_session_skip_update ⇒ Object
Filter to disable updating of the session cookie.
-
#log_processing_with_global_session ⇒ Object
Override for the ActionController method of the same name that logs information about the request.
Class Method Details
.included(base) ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 38 def self.included(base) # :nodoc: #Make sure a superclass hasn't already chained the methods... unless base.instance_methods.include?("log_processing_without_global_session") base.alias_method_chain :log_processing, :global_session end base.before_filter :global_session_initialize end |
Instance Method Details
#global_session ⇒ Object
Global session reader.
Return
- session(Session)
-
the global session associated with the current request, nil if none
63 64 65 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 63 def global_session @global_session end |
#global_session_config ⇒ Object
Shortcut accessor for global session configuration object.
Return
config(GlobalSession::Configuration)
51 52 53 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 51 def global_session_config request.env['global_session.config'] end |
#global_session_initialize ⇒ Object
Filter to initialize the global session.
Return
- true
-
Always returns true
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 71 def global_session_initialize = if [:only] && ![:only].include?(action_name) should_skip = true elsif [:except] && [:except].include?(action_name) should_skip = true elsif ![:enabled] should_skip = true end if should_skip request.env['global_session.req.renew'] = false request.env['global_session.req.update'] = false else error = request.env['global_session.error'] raise error unless error.nil? || [:raise] == false @global_session = request.env['global_session'] end return true end |
#global_session_options ⇒ Object
55 56 57 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 55 def self.class. end |
#global_session_skip_renew ⇒ Object
Filter to disable auto-renewal of the session.
Return
- true
-
Always returns true
98 99 100 101 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 98 def global_session_skip_renew request.env['global_session.req.renew'] = false true end |
#global_session_skip_update ⇒ Object
Filter to disable updating of the session cookie
Return
- true
-
Always returns true
107 108 109 110 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 107 def global_session_skip_update request.env['global_session.req.update'] = false true end |
#log_processing_with_global_session ⇒ Object
Override for the ActionController method of the same name that logs information about the request. Our version logs the global session ID instead of the local session ID.
Parameters
- name(Type)
-
Description
Return
- name(Type)
-
Description
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 121 def log_processing_with_global_session return unless logger && logger.info? gs = request.env['global_session'] if gs && gs.id session_data = {} gs.each_pair { |key, value| session_data[key] = value } session_id = gs.id + " (#{session[:session_id] || request.[:id]})" elsif session[:session_id] session_id = session[:session_id] elsif request.[:id] session_id = request.[:id] end request_id = "\n\nProcessing #{self.class.name}\##{action_name} " request_id << "to #{params[:format]} " if params[:format] request_id << "(for #{request_origin.split[0]}) [#{request.method.to_s.upcase}]" request_id << "\n Session ID: #{session_id}" if session_id request_id << "\n Session Data: #{session_data.inspect}" if session_data logger.info(request_id) parameters = respond_to?(:filter_parameters, true) ? filter_parameters(params) : params.dup parameters = parameters.except!(:controller, :action, :format, :_method) logger.info " Parameters: #{parameters.inspect}" unless parameters.empty? end |