Sha256: 5dda306c0c99480a9410ec863c17b3675c926a0f8c8b2bb69bf2c08e898cebf3

Contents?: true

Size: 1.79 KB

Versions: 55

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module BoltSpec
  module Plans
    class DownloadStub < 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
              download = File.join(destination, Bolt::Util.windows_basename(source))
              Bolt::Result.for_download(target, source, destination, download)
            end
          end
          Bolt::ResultSet.new(results)
        end
      end

      def parameters
        @invocation[:options]
      end

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

      # Public methods

      def always_return(_data)
        raise 'Download 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?('_') }
                                      .transform_keys { |k| k.sub(/^_/, '').to_sym }
        self
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
bolt-3.22.1 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.22.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.21.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.20.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.19.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.18.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.17.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.16.1 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.16.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.15.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.14.1 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.13.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.12.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.11.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.10.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.9.2 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.9.1 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.9.0 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.8.1 lib/bolt_spec/plans/action_stubs/download_stub.rb
bolt-3.8.0 lib/bolt_spec/plans/action_stubs/download_stub.rb