class SyncWrap::ChangeGuard

Maintains a remote guard file to preserve change_key state across any transient failures which might occur in subsequent components up until a paired ChangeUnGuard.

Components which rely on change key state (via ChangeKeyListener mixin or otherwise) may loose state due to transient failure and thus remain out-of-sync on subsequent runs. This is particularly common during concurrent development of such components.

Typical usage using SourceTree as the change producer and Bundle as one of possibly several consumers:

role( :my_role,
      SourceTree.new( change_key: :src_key ),
      *ChangeGuard.new( change_key: :src_key ).wrap(
        Bundle.new( change_key: :src_key ),
        # ...
      ) )

Host component dependencies: RunUser, SourceTree?

Attributes

change_guard_file[W]

Remote path and file name to use as the guard file (Default: SyncWrap::SourceTree#remote_source_path + '.changed')

Public Class Methods

new( opts = {} ) click to toggle source
Calls superclass method SyncWrap::ChangeKeyListener.new
# File lib/syncwrap/components/change_guard.rb, line 58
def initialize( opts = {} )
  @change_guard_file = nil
  super
end

Public Instance Methods

change_guard_file() click to toggle source
# File lib/syncwrap/components/change_guard.rb, line 54
def change_guard_file
  @change_guard_file || "#{remote_source_path}.changed"
end
install() click to toggle source
# File lib/syncwrap/components/change_guard.rb, line 63
    def install
      if change_key_changes?
        rudo <<-SH
          touch #{change_guard_file}
        SH
      else
        code,_ = capture( "          if [ -f "#{change_guard_file}" ]; then
            exit 92
          fi
", user: run_user, accept: [0,92] )
        if code == 92
          Array( change_key ).each do |key|
            state[ key ] ||= []
            state[ key ] << [ '*found', change_guard_file ]
          end
        end
      end
    end
wrap( *nested_components ) click to toggle source

Convenience method for constructed an array of [ ChangeGuard, *nested_components, ChangeUnGuard ].

# File lib/syncwrap/components/change_guard.rb, line 46
def wrap( *nested_components )
  [ self, *nested_components, ChangeUnGuard.new ]
end