Sha256: 7bc0c4cf63b5cba0b85994f3f6f6e775a49f5495d61baee4f89a189442f842c4

Contents?: true

Size: 738 Bytes

Versions: 13

Compression:

Stored size: 738 Bytes

Contents

module Mocktail
  class ValidatesArguments
    def self.disable!
      Thread.current[:mocktail_arity_validation_disabled] = true
    end

    def self.enable!
      Thread.current[:mocktail_arity_validation_disabled] = false
    end

    def self.disabled?
      Thread.current[:mocktail_arity_validation_disabled]
    end

    def self.optional(disable, &blk)
      return blk.call unless disable

      disable!
      blk.call.tap do
        enable!
      end
    end

    def initialize
      @simulates_argument_error = SimulatesArgumentError.new
    end

    def validate(dry_call)
      return if self.class.disabled?

      if (error = @simulates_argument_error.simulate(dry_call))
        raise error
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mocktail-1.2.3 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.2.2 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.2.1 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.2.0 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.1.3 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.1.2 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.1.1 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.1.0 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-1.0.0 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-0.0.6 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-0.0.5 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-0.0.4 lib/mocktail/handles_dry_call/validates_arguments.rb
mocktail-0.0.3 lib/mocktail/handles_dry_call/validates_arguments.rb