Sha256: d4d3e0e41fb006c4ba3368150799f97f923e7c78d09c7af94994aec49ec1d99a

Contents?: true

Size: 796 Bytes

Versions: 7

Compression:

Stored size: 796 Bytes

Contents

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

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

      def to_s
        "allow when custom rule (#{@options[:description]}) returns true"
      end

      def authorized?(controller_instance, controller, action, id)
        unless @block.nil?
          result = @block.call(controller_instance)
          return true unless result == false || result.nil?
        end
        return false
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
role_authorization-0.1.6 lib/role_authorization/rules/custom.rb
role_authorization-0.1.5 lib/role_authorization/rules/custom.rb
role_authorization-0.1.4 lib/role_authorization/rules/custom.rb
role_authorization-0.1.3 lib/role_authorization/rules/custom.rb
role_authorization-0.1.2 lib/role_authorization/rules/custom.rb
role_authorization-0.1.1 lib/role_authorization/rules/custom.rb
role_authorization-0.1.0 lib/role_authorization/rules/custom.rb