Sha256: 10480aa63b894c93498b39720f519df2300fa82f859cc03336f563808cd74a8d

Contents?: true

Size: 1.69 KB

Versions: 19

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module BoltSpec
  module Plans
    class UploadStub < ActionStub
      def matches(targets, _source, destination, options)
        if @invocation[:targets] && Set.new(@invocation[:targets]) != Set.new(targets.map(&:name))
          return false
        end

        if @invocation[:destination] && destination != @invocation[:destination]
          return false
        end

        if @invocation[:options] && options != @invocation[:options]
          return false
        end

        true
      end

      def call(targets, source, destination, options)
        @calls += 1
        if @return_block
          results = @return_block.call(targets: targets, source: source, destination: destination, params: options)
          check_resultset(results, source)
        else
          results = targets.map do |target|
            if @data[:default].is_a?(Bolt::Error)
              default_for(target)
            else
              Bolt::Result.for_upload(target, source, destination)
            end
          end
          Bolt::ResultSet.new(results)
        end
      end

      def parameters
        @invocation[:options]
      end

      def result_for(_target, _data)
        raise 'Upload result cannot be changed'
      end

      # Public methods

      def always_return(_data)
        raise 'Upload result cannot be changed'
      end

      def with_destination(destination)
        @invocation[:destination] = destination
        self
      end

      def with_params(params)
        @invocation[:options] = params.select { |k, _v| k.start_with?('_') }
                                      .map { |k, v| [k.sub(/^_/, '').to_sym, v] }.to_h
        self
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bolt-2.1.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-2.0.1 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-2.0.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.49.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.48.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.47.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.45.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.44.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.43.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.42.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.41.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.40.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.39.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.38.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.37.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.36.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.35.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.34.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.33.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb