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

Instance Method Summary collapse

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_sessionObject

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_configObject

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_initializeObject

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
  options = global_session_options

  if options[:only] && !options[:only].include?(action_name)
    should_skip = true
  elsif options[:except] && options[:except].include?(action_name)
    should_skip = true
  elsif !options[: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? || options[:raise] == false
    @global_session = request.env['global_session']
  end

  return true
end

#global_session_optionsObject



55
56
57
# File 'lib/global_session/rails/action_controller_instance_methods.rb', line 55

def global_session_options
  self.class.global_session_options
end

#global_session_skip_renewObject

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_updateObject

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_sessionObject

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.session_options[:id]})"
  elsif session[:session_id]
    session_id = session[:session_id]
  elsif request.session_options[:id]
    session_id = request.session_options[: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