Module: GlobalSession::Rails::ActionControllerClassMethods

Defined in:
lib/global_session/rails/action_controller_class_methods.rb

Overview

Module that is mixed into ActionController’s eigenclass; provides access to shared app-wide data such as the configuration object, and implements the DSL used to configure controllers’ use of the global session.

Constant Summary collapse

VALID_OPTIONS =
[:raise, :renew, :only, :except]
DEFAULT_OPTIONS =
{
  :raise=>true,
  :renew=>true
}

Instance Method Summary collapse

Instance Method Details

#global_session_optionsObject



62
63
64
65
66
67
68
69
70
# File 'lib/global_session/rails/action_controller_class_methods.rb', line 62

def global_session_options
  if @global_session_options
    @global_session_options
  elsif self.superclass.respond_to?(:global_session_options)
    self.superclass.global_session_options
  else
    {}
  end
end

#global_session_options=(options) ⇒ Object



72
73
74
# File 'lib/global_session/rails/action_controller_class_methods.rb', line 72

def global_session_options=(options)
  @global_session_options = options
end

#has_global_session(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/global_session/rails/action_controller_class_methods.rb', line 34

def has_global_session(options={})
  #validate our options
  options.assert_valid_keys(VALID_OPTIONS)
  if options.key?(:only) && options.key?(:except)
    raise ArgumentError, "Must specify :only OR :except, you specified both"
  end

  #start with default options; merge any options inherited from our base class;
  #merge any options provided by the caller.
  obase   = self.superclass.global_session_options
  options = DEFAULT_OPTIONS.merge(obase).merge(options)

  #ensure derived-class options don't conflict with mutually exclusive base-class options
  options.delete(:only) if obase.has_key?(:only) && options.has_key?(:except)
  options.delete(:except) if obase.has_key?(:except) && options.has_key?(:only)

  #mark the global session as enabled (a hidden option) and store our
  #calculated, merged options
  options[:enabled] = true

  self.global_session_options = options
end

#no_global_sessionObject



57
58
59
60
# File 'lib/global_session/rails/action_controller_class_methods.rb', line 57

def no_global_session
  #mark the global session as not-enabled (a hidden option)
  self.global_session_options={:enabled=>false}
end