Sha256: 3836edfe52a1931765cf10dd82c84ba903e49815ef65ed77d2a374f583bba950

Contents?: true

Size: 959 Bytes

Versions: 42

Compression:

Stored size: 959 Bytes

Contents

require_relative './task_exception'

module Builderator
  module Util
    ##
    # Exception raised if a safety limit is exceeded
    ##
    class LimitException < TaskException
      DEFAULT_LIMIT = 4

      attr_reader :resource_name
      attr_reader :resources

      def initialize(resource_name, task, resources)
        super(:limit, task, :yellow)

        @resource_name = resource_name
        @resources = resources
      end

      def count
        @resources.size
      end

      def limit
        Config.cleaner.limits[resource_name]
      end

      def message
        msg = "Safety limit exceeded for task `#{task}`: Count #{count} is "
        msg << "greater than the limit of #{limit} set in `cleaner.limits.#{resource_name}`. "
        msg << 'Please re-run this task with the --force flag if you are sure this is '\
        'the correct set of resources to delete.' unless Config.cleaner.force

        msg
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
builderator-1.0.0.pre.rc.3 lib/builderator/util/limit_exception.rb
builderator-1.0.0.pre.rc.1 lib/builderator/util/limit_exception.rb