Class: TerraspaceBundler::Syncer
- Inherits:
-
Object
- Object
- TerraspaceBundler::Syncer
- Includes:
- TB::Util::Logging
- Defined in:
- lib/terraspace_bundler/syncer.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(options = {}) ⇒ Syncer
constructor
A new instance of Syncer.
- #lockfile ⇒ Object
- #run ⇒ Object
- #subtract(mods1, mods2) ⇒ Object
- #sync ⇒ Object
- #sync?(mod) ⇒ Boolean
- #sync_mods ⇒ Object
- #terrafile ⇒ Object
- #update_all? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Syncer
Returns a new instance of Syncer.
5 6 7 8 |
# File 'lib/terraspace_bundler/syncer.rb', line 5 def initialize(={}) @options = @mod_name = @options[:mod] end |
Instance Method Details
#create ⇒ Object
28 29 30 |
# File 'lib/terraspace_bundler/syncer.rb', line 28 def create sync_mods end |
#lockfile ⇒ Object
66 67 68 |
# File 'lib/terraspace_bundler/syncer.rb', line 66 def lockfile Lockfile.instance end |
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/terraspace_bundler/syncer.rb', line 10 def run validate! FileUtils.rm_f(TB.config.lockfile) if update_all? logger.info "Bundling with #{TB.config.terrafile}..." if File.exist?(TB.config.lockfile) sync else create end TB::Lockfile.write end |
#subtract(mods1, mods2) ⇒ Object
57 58 59 60 |
# File 'lib/terraspace_bundler/syncer.rb', line 57 def subtract(mods1, mods2) mod2_names = mods2.map(&:name) mods1.select {|mod1| !mod2_names.include?(mod1.name) } end |
#sync ⇒ Object
22 23 24 25 26 |
# File 'lib/terraspace_bundler/syncer.rb', line 22 def sync sync_mods removed_mods = subtract(lockfile.mods, terrafile.mods) lockfile.prune(removed_mods) end |
#sync?(mod) ⇒ Boolean
41 42 43 44 |
# File 'lib/terraspace_bundler/syncer.rb', line 41 def sync?(mod) names = @options[:mods] names.blank? or names.include?(mod.name) end |
#sync_mods ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/terraspace_bundler/syncer.rb', line 32 def sync_mods # VersionComparer is used in lockfile.sync and does heavy lifting to check if mod should be updated and replaced terrafile.mods.each do |mod| next unless sync?(mod) logger.debug "Syncing #{mod.name}" lockfile.sync(mod) # update (if version mismatch) or create (if missing) end end |
#terrafile ⇒ Object
62 63 64 |
# File 'lib/terraspace_bundler/syncer.rb', line 62 def terrafile Terrafile.instance end |
#update_all? ⇒ Boolean
53 54 55 |
# File 'lib/terraspace_bundler/syncer.rb', line 53 def update_all? TB.update_mode? && @options[:mods].empty? end |
#validate! ⇒ Object
46 47 48 49 50 51 |
# File 'lib/terraspace_bundler/syncer.rb', line 46 def validate! return unless terrafile.missing_org? logger.error "ERROR: org must be set in the #{TB.config.terrafile}.".color(:red) logger.error "Please set org in the Terrafile" exit 1 end |