Sha256: 73ef2abefe67756ca2e77af735f630b800e248fa0bdf8bb729e4de8a1267f46d

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

class Lono::Bundler::Lockfile
  class VersionComparer
    attr_reader :reason, :changed
    def initialize(locked, current)
      @locked, @current = locked, current
      @changed = false
    end

    def changed?
      @changed
    end

    # Tricky logic, maybe spec this.
    #
    #   no components specified:
    #     lono bundle update  # no components specified => update all
    #     lono bundle install # no Lonofile.lock => update all
    #   components specified:
    #     lono bundle update s3  # explicit component => update s3
    #     lono bundle install s3 # errors: not possible to specify componentule for install command
    #
    # Note: Install with specific components wipes existing components. Not worth it to support.
    #
    def run
      @changed = false

      # Most props are "strict" version checks. So if user changes options generally in the component line
      # the Lonofile.lock will get updated, which is expected behavior.
      props = @locked.props.keys + @current.props.keys
      strict_versions = props.uniq.sort - [:sha, :type]
      strict_versions.each do |version|
        @changed = @locked.send(version) != @current.send(version)
        if @changed
          @reason = reason_message(version)
          return @changed
        end
      end

      # Lots of nuance with the sha check that works differently
      # Only check when set.
      # Also in update mode then always check it.
      @changed = @current.sha && !@locked.sha.include?(@current.sha) ||
                 LB.update_mode? && !@current.latest_sha.include?(@locked.sha)
      if @changed
        @reason = reason_message("sha")
        return @changed
      end

      @changed
    end

    def reason_message(version)
      "Replacing component #{@current.name} because #{version} is different in Lonofile and Lonofile.lock"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lono-8.0.0.pre.rc6 lib/lono/bundler/lockfile/version_comparer.rb
lono-8.0.0.pre.rc5 lib/lono/bundler/lockfile/version_comparer.rb
lono-8.0.0.pre.rc4 lib/lono/bundler/lockfile/version_comparer.rb
lono-8.0.0.pre.rc3 lib/lono/bundler/lockfile/version_comparer.rb
lono-8.0.0.pre.rc2 lib/lono/bundler/lockfile/version_comparer.rb
lono-8.0.0.pre.rc1 lib/lono/bundler/lockfile/version_comparer.rb