Sha256: 5400619c70cfbac272520469a2d34b99d285d2a5c0834634e1681a725831d87d

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

module CanTango
  class Configuration
    class Guest
      include Singleton

      def clear!
        @user = nil
        @account = nil
      end

      def user user = nil, &block
        return (@user || guest_user) if !user && !block
        @user = user || yield
      end

      alias_method :user=, :user

      def account account = nil, &block
        return (@account || guest_account) if !account && !block
        @account = account || yield
      end

      alias_method :account=, :account

      def default_user?
        has_guest? base_user_class
      end

      def default_account?
        has_guest? base_account_class
      end

      protected

      def guest_user
        base_user_class.guest if default_user?
      end

      def guest_account
        base_account_class.guest if default_account?
      end

      def has_guest? clazz
        clazz && defined?(clazz) && clazz.respond_to?(:guest)
      end

      def base_user_class
        CanTango.config.user.base_class
      end

      def base_account_class
        CanTango.config.user_account.base_class
      end
    end
  end
end
 

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cantango-0.8.9.5 lib/cantango/configuration/guest.rb
cantango-0.8.9.4 lib/cantango/configuration/guest.rb
cantango-0.8.9.3 lib/cantango/configuration/guest.rb
cantango-0.8.9.2 lib/cantango/configuration/guest.rb
cantango-0.8.9.1 lib/cantango/configuration/guest.rb
cantango-0.8.9 lib/cantango/configuration/guest.rb
cantango-0.8.8.1 lib/cantango/configuration/guest.rb
cantango-0.8.8 lib/cantango/configuration/guest.rb
cantango-0.8.7 lib/cantango/configuration/guest.rb
cantango-0.8.6.2 lib/cantango/configuration/guest.rb
cantango-0.8.6.1 lib/cantango/configuration/guest.rb
cantango-0.8.6 lib/cantango/configuration/guest.rb
cantango-0.8.5.1 lib/cantango/configuration/guest.rb
cantango-0.8.0 lib/cantango/configuration/guest.rb