Sha256: 8a00af96f0996a962894e3781b27792e49c5a9cb0e8ea4f74d5e1dc631b9d843

Contents?: true

Size: 1.49 KB

Versions: 27

Compression:

Stored size: 1.49 KB

Contents

#
# When running in pactfile_write_mode :overwrite, all interactions are cleared from the
# pact file, and all new interactions should be distinct (unique description and provider state).
# When running in pactfile_write_mode :update, an interaction with the same description
# and provider state as an existing one will just overwrite that one interaction.
#

module Pact
   module Consumer

      #TODO: think of a better word than filter
      class InteractionsFilter
         def initialize interactions = []
            @interactions = interactions
         end

         def index_of interaction
            @interactions.find_index{ |i| i.matches_criteria?(description: interaction.description, provider_state: interaction.provider_state)}
         end
      end

      class UpdatableInteractionsFilter < InteractionsFilter

         def << interaction
            if (ndx = index_of(interaction))
               @interactions[ndx] = interaction
            else
               @interactions << interaction
            end
         end

      end

      class DistinctInteractionsFilter < InteractionsFilter

         def << interaction
            if (ndx = index_of(interaction))
               if @interactions[ndx] != interaction
                  raise "Interaction with same description (#{interaction.description}) and provider state (#{interaction.provider_state}) already exists"
               end
            else
               @interactions << interaction
            end
         end
      end

   end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
pact-mock_service-0.2.2 lib/pact/consumer/interactions_filter.rb
pact-mock_service-0.2.1 lib/pact/consumer/interactions_filter.rb
pact-mock_service-0.2.0 lib/pact/consumer/interactions_filter.rb
pact-mock_service-0.1.0 lib/pact/consumer/interactions_filter.rb
pact-mock_service-0.0.1 lib/pact/consumer/interactions_filter.rb
pact-1.3.3 lib/pact/consumer/interactions_filter.rb
pact-1.3.2 lib/pact/consumer/interactions_filter.rb
pact-1.3.1 lib/pact/consumer/interactions_filter.rb
pact-1.3.0 lib/pact/consumer/interactions_filter.rb
pact-1.2.1.rc2 lib/pact/consumer/interactions_filter.rb
pact-1.2.1.rc1 lib/pact/consumer/interactions_filter.rb
pact-1.1.1 lib/pact/consumer/interactions_filter.rb
pact-1.1.0 lib/pact/consumer/interactions_filter.rb
pact-1.1.0.rc5 lib/pact/consumer/interactions_filter.rb
pact-1.1.0.rc4 lib/pact/consumer/interactions_filter.rb
pact-1.1.0.rc3 lib/pact/consumer/interactions_filter.rb
pact-1.0.39 lib/pact/consumer/interactions_filter.rb
pact-1.1.0.rc2 lib/pact/consumer/interactions_filter.rb
pact-1.0.38 lib/pact/consumer/interactions_filter.rb
pact-1.1.0.rc1 lib/pact/consumer/interactions_filter.rb