Class: TerraspaceBundler::Lockfile::VersionComparer

Inherits:
Object
  • Object
show all
Defined in:
lib/terraspace_bundler/lockfile/version_comparer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locked, current) ⇒ VersionComparer

Returns a new instance of VersionComparer.



4
5
6
7
# File 'lib/terraspace_bundler/lockfile/version_comparer.rb', line 4

def initialize(locked, current)
  @locked, @current = locked, current
  @changed = false
end

Instance Attribute Details

#changedObject (readonly)

Returns the value of attribute changed.



3
4
5
# File 'lib/terraspace_bundler/lockfile/version_comparer.rb', line 3

def changed
  @changed
end

#reasonObject (readonly)

Returns the value of attribute reason.



3
4
5
# File 'lib/terraspace_bundler/lockfile/version_comparer.rb', line 3

def reason
  @reason
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/terraspace_bundler/lockfile/version_comparer.rb', line 9

def changed?
  @changed
end

#reason_message(version) ⇒ Object



52
53
54
# File 'lib/terraspace_bundler/lockfile/version_comparer.rb', line 52

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

#runObject

Tricky logic, maybe spec this.

no mods specified:
  terraspace bundle update  # no mods specified => update all
  terraspace bundle install # no Terrafile.lock => update all
mods specified:
  terraspace bundle update s3  # explicit mod => update s3
  terraspace bundle install s3 # errors: not possible to specify module for install command

Note: Install with specific mods wipes existing mods. Not worth it to support.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/terraspace_bundler/lockfile/version_comparer.rb', line 24

def run
  @changed = false

  # Most props are "strict" version checks. So if user changes options generally in the mod line
  # the Terrafile.lock will get updated, which is expected behavior.
  props = @locked.props.keys + @current.props.keys
  strict_versions = props.uniq.sort - [:sha]
  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) ||
             TB.update_mode? && !@current.latest_sha.include?(@locked.sha)
  if @changed
    @reason = reason_message("sha")
    return @changed
  end

  @changed
end