Sha256: da1bd038ea4690912b418e5255a14ad326697b39790a0dfcb4469577bbae842c

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

module Kindergarten
  # Signals unallowed access
  class AccessDenied < CanCan::AccessDenied
    def initialize(action, target, opts)
      message = opts.delete(:message)
      if message.blank?
        name    = target.is_a?(Class) ? target.name : target.class.name
        message = "You are not allowed to #{action} that #{name.downcase}"
      end

      super(message, action, target)
    end
  end

  class Sandbox
    class NoPurposeError < NoMethodError
      def initialize(purpose, sandbox)
        @purpose = purpose
        @sandbox = sandbox
      end

      def to_s
        "undefined purpose '#{@purpose}' for #{@sandbox}"
      end
    end
  end

  class Perimeter
    class NoExposedMethods < NoMethodError
      def initialize(perimeter)
        @perimeter = perimeter
        super
      end

      def to_s
        "The module #{@perimeter.name} does not expose any methods."
      end
    end

    class NoPurpose < ArgumentError
      def initialize(perimeter)
        @perimeter = perimeter
        super
      end

      def to_s
        "The module #{@perimeter.name} does not have a purpose."
      end
    end

    class RestrictedMethodError < ArgumentError
      def initialize(perimeter, method)
        @perimeter = perimeter
        @method    = method
      end

      def to_s
        "You exposed '#{method}' on the #{perimeter}, but that is a restricted method"
      end
    end

    # Signals bad sandbox method implementation
    class Unguarded < SecurityError; end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kindergarten-0.2.1 lib/kindergarten/exceptions.rb
kindergarten-0.2.0 lib/kindergarten/exceptions.rb
kindergarten-0.1.1 lib/kindergarten/exceptions.rb