Sha256: ed334d59185a0bbda54a6c1612e8acda90309f937a88715f7db0c6cec3d29b08

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

module GlobalSession
  module Rails
    # 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.
    module ActionControllerClassMethods
      def global_session_config
        unless @global_session_config
          config_file = File.join(::Rails.root, 'config', 'global_session.yml')
          @global_session_config = GlobalSession::Configuration.new(config_file, RAILS_ENV)
        end

        return @global_session_config
      end

      def global_session_config=(config)
        @global_session_config = config
      end

      def has_global_session(options={})
        odefault = {:integrated=>false, :raise=>true}
        obase = self.superclass.global_session_options if self.superclass.respond_to?(:global_session_options)
        obase ||= {}
        options = odefault.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

        before_filter :global_session_initialize
      end

      def no_global_session
        @global_session_options[:enabled] = false if @global_session_options
        skip_before_filter :global_session_initialize
      end

      def global_session_options
        obase = self.superclass.global_session_options if self.superclass.respond_to?(:global_session_options) 
        obase ||= {}
        @global_session_options || obase
      end

      def global_session_options=(options)
        @global_session_options = options
      end      
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
global_session-1.0.8 lib/global_session/rails/action_controller_class_methods.rb
global_session-1.0.7 lib/global_session/rails/action_controller_class_methods.rb
global_session-1.0.6 lib/global_session/rails/action_controller_class_methods.rb
global_session-1.0.5 lib/global_session/rails/action_controller_class_methods.rb
global_session-1.0.4 lib/global_session/rails/action_controller_class_methods.rb
global_session-1.0.3 lib/global_session/rails/action_controller_class_methods.rb
global_session-1.0.2 lib/global_session/rails/action_controller_class_methods.rb
global_session-1.0.0 lib/global_session/rails/action_controller_class_methods.rb