Permalink
Browse files

Git rid of remaining references to Serializers and add deprecation wa…

…rnings.
  • Loading branch information...
1 parent 8a4dd51 commit a82a4a36dc57749ec6d3af879bda08cf1b913cdc @josevalim josevalim committed Jan 13, 2010
View
@@ -1,6 +1,5 @@
# encoding: utf-8
require 'forwardable'
-$:.unshift File.join(File.dirname(__FILE__))
require 'warden/mixins/common'
require 'warden/proxy'
@@ -9,10 +8,6 @@
require 'warden/session_serializer'
require 'warden/strategies'
require 'warden/strategies/base'
-require 'warden/serializers'
-require 'warden/serializers/base'
-require 'warden/serializers/cookie'
-require 'warden/serializers/session'
module Warden
class NotAuthenticated < StandardError; end
View
@@ -34,10 +34,8 @@ def #{name}=(value)
def initialize(other={})
merge!(other)
-
self[:default_scope] ||= :default
self[:default_strategies] ||= []
- self[:default_serializers] ||= [ :session ]
end
# Do not raise an error if a missing strategy is given by default.
@@ -50,16 +48,6 @@ def silence_missing_strategies? #:nodoc:
!!self[:silence_missing_strategies]
end
- # Do not raise an error if a missing serializer is given by default.
- # :api: plugin
- def silence_missing_serializers!
- self[:silence_missing_serializers] = true
- end
-
- def silence_missing_serializers? #:nodoc:
- !!self[:silence_missing_serializers]
- end
-
# Set the default strategies to use.
# :api: public
def default_strategies(*strategies)
@@ -70,22 +58,6 @@ def default_strategies(*strategies)
end
end
- # Set the default serializers to use. By default, only session is enabled.
- # :api: public
- def default_serializers(*serializers)
- if serializers.empty?
- self[:default_serializers]
- else
- self[:default_serializers] = serializers.flatten
- end
- end
-
- # Quick accessor to strategies from manager
- # :api: public
- def serializers
- Warden::Serializers
- end
-
# Quick accessor to strategies from manager
# :api: public
def strategies
View
@@ -1,43 +0,0 @@
-# encoding: utf-8
-module Warden
- module Declarable
-
- # Add a declaration and store it in a hash.
- def add(label, declaration = nil, &block)
- base = self.const_get(:Base)
-
- declaration ||= Class.new(base)
- declaration.class_eval(&block) if block_given?
-
- check_validity!(label, declaration)
- raise "#{label.inspect} is not a #{base}" unless declaration.ancestors.include?(base)
-
- _declarations[label] = declaration
- end
-
- # Update a previously given declaration.
- def update(label, &block)
- declaration = _declarations[label]
- raise "Unknown declaration #{label.inspect}" unless declaration
- add(label, declaration, &block)
- end
-
- # Provides access to declarations by label
- # :api: public
- def [](label)
- _declarations[label]
- end
-
- # Clears all declared.
- # :api: public
- def clear!
- _declarations.clear
- end
-
- # :api: private
- def _declarations
- @declarations ||= {}
- end
-
- end # Declarable
-end # Warden
View
@@ -16,8 +16,8 @@ def _run_callbacks(kind, *args) #:nodoc:
end
# A callback hook set to run every time after a user is set.
- # This callback is triggered the first time one of those three events happens during a request:
- # :authentication, :fetch (from one of the serializers, like session) and :set_user (when manually set).
+ # This callback is triggered the first time one of those three events happens
+ # during a request: :authentication, :fetch (from session) and :set_user (when manually set).
# You can supply as many hooks as you like, and they will be run in order of decleration.
#
# If you want to run the callbacks for a given scope and/or event, you can specify them as options.
@@ -1,5 +1,22 @@
module Warden
module ManagerDeprecation
+ class Dummy
+ def update(type, &block)
+ if type == :session
+ warn "[DEPRECATION] warden.serializers.update(:session) is deprecated. " <<
+ "Please use Warden::Manager.serialize_from_session and Warden::Manager.serialize_into_session"
+ Warden::SessionSerializer.class_eval(&block)
+ else
+ method_missing(update)
+ end
+ end
+
+ def method_missing(method, *args)
+ warn "[DEPRECATION] warden.serializers.#{method} is deprecated."
+ nil
+ end
+ end
+
# Read the default scope from Warden
def default_scope
warn "[DEPRECATION] Warden::Manager.default_scope is deprecated. It's now accessible in the Warden::Manager instance."
@@ -9,5 +26,10 @@ def default_scope
def default_scope=(scope)
warn "[DEPRECATION] Warden::Manager.default_scope= is deprecated. Please set it in the Warden::Manager instance."
end
+
+ def serializers
+ warn "[DEPRECATION] warden.serializers is deprecated since Warden::Serializers were merged into Warden::Strategies."
+ Dummy.new
+ end
end
end
View
@@ -1,18 +1,46 @@
# encoding: utf-8
-require 'warden/declarable'
-
module Warden
module Strategies
- extend Warden::Declarable
-
class << self
- def check_validity!(label, strategy)
- return if strategy.method_defined?(:authenticate!)
- raise NoMethodError, "authenticate! is not declared in the #{label.inspect} strategy"
+ # Add a strategy and store it in a hash.
+ def add(label, strategy = nil, &block)
+ strategy ||= Class.new(Warden::Strategies::Base)
+ strategy.class_eval(&block) if block_given?
+
+ unless strategy.method_defined?(:authenticate!)
+ raise NoMethodError, "authenticate! is not declared in the #{label.inspect} strategy"
+ end
+
+ unless strategy.ancestors.include?(Warden::Strategies::Base)
+ raise "#{label.inspect} is not a #{base}"
+ end
+
+ _strategies[label] = strategy
+ end
+
+ # Update a previously given strategy.
+ def update(label, &block)
+ strategy = _strategies[label]
+ raise "Unknown strategy #{label.inspect}" unless strategy
+ add(label, strategy, &block)
end
-
- alias :_strategies :_declarations
- end # << self
+ # Provides access to strategies by label
+ # :api: public
+ def [](label)
+ _strategies[label]
+ end
+
+ # Clears all declared.
+ # :api: public
+ def clear!
+ _strategies.clear
+ end
+
+ # :api: private
+ def _strategies
+ @strategies ||= {}
+ end
+ end # << self
end # Strategies
end # Warden
View
@@ -1,9 +1,11 @@
$TESTING=true
-require 'rubygems'
-require 'rack'
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'warden'
+require 'rubygems'
+require 'rack'
+
Dir[File.join(File.dirname(__FILE__), "helpers", "**/*.rb")].each do |f|
require f
end
View
@@ -23,26 +23,11 @@
@config.default_strategies.should == [:foo, :bar]
end
- it "should allow to read and set default serializers" do
- @config.default_serializers :foo, :bar
- @config.default_serializers.should == [:foo, :bar]
- end
-
- it "should ship with default serializers and strategies" do
- @config.default_strategies.should == []
- @config.default_serializers.should == [:session]
- end
-
it "should allow to silence missing strategies" do
@config.silence_missing_strategies!
@config.silence_missing_strategies?.should be_true
end
- it "should allow to silence missing serializers" do
- @config.silence_missing_serializers!
- @config.silence_missing_serializers?.should be_true
- end
-
it "should set the default_scope" do
@config.default_scope.should == :default
@config.default_scope = :foo

0 comments on commit a82a4a3

Please sign in to comment.