module CanTango::Api
  module Scope
    module User
      include CanTango::Api::Ability::User
      
      def scope_user scope, options = {}, &block
        user = scoped_user(scope)
        ab_scope = user_ability_scope(user, options)
        yield ab_scope if block
        ab_scope
      end
      alias_method :user_scope, :scope_user

      def real_user scope, options = {}, &block
        scope_user scope, options.merge(:masquerade => false), &block
      end

      protected

      def user_ability_scope user, options = {}
        CanTango::Scope::Ability.new user_ability(user, options)
      end

      def scoped_user scope
        send(:"current_#{scope}")
      end
    end
  end
end
