Sha256: 208b325f3ea51fef48a0bc012930c72909986f4ebe9c6ed881bfacb30a976d5c

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

module RoleAuthorization
  # define our rule helper in Mapper
  class Mapper
    def logged_in(options={}, &block)
      options.assert_valid_keys(:only)
      rule(:logged_in, :logged_in, options, &block)
    end
  end

  module Exts
    module View
      def logged_in(&block)
        if block_given? && !current_user.anonymous?
          capture_haml(&block)
        end
      end
    end
  end

  module Rules
    class LoggedIn < Basic
      def initialize(controller, options, &block)
        @controller_klass = controller
        @options = options
        self
      end

      def to_s
        "allow when current_user is logged in (not anonymous)"
      end

      def authorized?(controller_instance, controller, action, id)
        return true unless controller_instance.current_user.anonymous?
        return false
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
role_authorization-0.1.1 lib/role_authorization/rules/logged_in.rb
role_authorization-0.1.0 lib/role_authorization/rules/logged_in.rb