Sha256: fd0be34a4c7bc44ff798b82ac6621afcd9d595350e5fc26209753d17e2c28092

Contents?: true

Size: 1014 Bytes

Versions: 27

Compression:

Stored size: 1014 Bytes

Contents

require 'pact_broker/configuration'

module PactBroker
  module Domain
    class OrderVersions

      def self.call pacticipant_id
        orderable_versions = PactBroker::Domain::Version.where(:pacticipant_id => pacticipant_id).all.collect{| version | OrderableVersion.new(version) }
        orderable_versions.sort.each_with_index{ | version, i | version.update_model(i) }
      end

      class OrderableVersion

        attr_accessor :version_model, :sortable_number

        def initialize version_model
          @version_model = version_model
          @sortable_number = PactBroker.configuration.version_parser.call version_model.number
        end

        def <=> other
          self.sortable_number <=> other.sortable_number
        end

        def update_model new_order
          # Sequel will only run the update if the column value has changed, so in 99% of
          # cases, only one update will occur.
          version_model.update(:order => new_order)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
pact_broker-2.0.0.beta.6 lib/pact_broker/domain/order_versions.rb
pact_broker-2.0.0.beta.5 lib/pact_broker/domain/order_versions.rb
pact_broker-1.18.0.beta.1 lib/pact_broker/domain/order_versions.rb
pact_broker-1.17.2 lib/pact_broker/domain/order_versions.rb
pact_broker-1.17.1 lib/pact_broker/domain/order_versions.rb
pact_broker-2.0.0.beta.4 lib/pact_broker/domain/order_versions.rb
pact_broker-2.0.0.beta.3 lib/pact_broker/domain/order_versions.rb
pact_broker-2.0.0.beta.2 lib/pact_broker/domain/order_versions.rb
pact_broker-2.0.0.beta.1 lib/pact_broker/domain/order_versions.rb
pact_broker-1.17.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.16.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.15.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.14.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.13.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.12.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.11.2 lib/pact_broker/domain/order_versions.rb
pact_broker-1.11.1 lib/pact_broker/domain/order_versions.rb
pact_broker-1.11.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.10.0 lib/pact_broker/domain/order_versions.rb
pact_broker-1.9.3 lib/pact_broker/domain/order_versions.rb