Class: TerraspaceBundler::Lockfile
- Inherits:
-
Object
- Object
- TerraspaceBundler::Lockfile
- Includes:
- Singleton, TB::Util::Logging
- Defined in:
- lib/terraspace_bundler/lockfile.rb,
lib/terraspace_bundler/lockfile/yamler.rb,
lib/terraspace_bundler/lockfile/version_comparer.rb
Defined Under Namespace
Classes: VersionComparer, Yamler
Constant Summary collapse
- @@mods =
{"sha"=>"52328b2b5197f9b95e3005cfcfb99595040ee45b", "source"=>"org/terraform-aws-vpc", "url"=>"https://github.com/org/terraform-aws-vpc",
“instance”=>
"source"=>"org/terraform-aws-instance", "url"=>"https://github.com/org/terraform-aws-instance"}
nil
Class Method Summary collapse
Instance Method Summary collapse
-
#changed?(mod) ⇒ Boolean
mod built from Terrafile.
- #mods ⇒ Object
- #new_mod(name, props) ⇒ Object
- #prune(removed_mods) ⇒ Object
- #replace!(mod) ⇒ Object
-
#sync(mod) ⇒ Object
update (if version mismatch) or create (if missing).
Class Method Details
Instance Method Details
#changed?(mod) ⇒ Boolean
mod built from Terrafile
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/terraspace_bundler/lockfile.rb', line 36 def changed?(mod) # missing module case found = mods.find { |locked_mod| locked_mod.name == mod.name } unless found logger.debug "Replacing mod: #{mod.name}. Not found in Terrafile.lock" return true end comparer = VersionComparer.new(found, mod) comparer.run logger.debug("REASON: #{comparer.reason}") if comparer.reason comparer.changed? end |
#mods ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/terraspace_bundler/lockfile.rb', line 17 def mods return @@mods if @@mods lockfile = TB.config.lockfile mods = File.exist?(lockfile) ? YAML.load_file(lockfile) : [] @@mods = mods.map do |name, props| new_mod(name, props) end end |
#new_mod(name, props) ⇒ Object
26 27 28 |
# File 'lib/terraspace_bundler/lockfile.rb', line 26 def new_mod(name, props) Mod.new(props.merge(name: name)) end |
#prune(removed_mods) ⇒ Object
57 58 59 60 |
# File 'lib/terraspace_bundler/lockfile.rb', line 57 def prune(removed_mods) removals = removed_mods.map(&:name) @@mods.delete_if { |m| removals.include?(m.name) } end |
#replace!(mod) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/terraspace_bundler/lockfile.rb', line 50 def replace!(mod) # mods are immediately fresh from writing to @@mods directly @@mods.delete_if { |m| m.name == mod.name } @@mods << mod @@mods.sort_by!(&:name) end |
#sync(mod) ⇒ Object
update (if version mismatch) or create (if missing)
31 32 33 |
# File 'lib/terraspace_bundler/lockfile.rb', line 31 def sync(mod) replace!(mod) if changed?(mod) end |