class DockerRailsProxy::Rsync::Sync

Attributes

rsync_host[R]

Public Class Methods

call(rsync_host:, **options) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 62
def self.call(rsync_host:, **options)
  new(rsync_host: rsync_host).sync(options)
end
new(rsync_host:) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 58
def initialize(rsync_host:)
  @rsync_host = rsync_host
end

Public Instance Methods

sync(options) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 66
def sync(options)
  return if source_in_exclusions?(**options)

  source, target, volume = normalize_options(**options)

  result = send(
    "sync_#{volume}", source: source, target: target, reverse: options[:reverse]
  )

  if result && options[:silent].eql?(false)
    DockerRailsProxy.logger.info "#{source}   =======>   #{target}"
  end

  result
end

Private Instance Methods

all_exclusions(reverse:) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 121
def all_exclusions(reverse:)
  one_way_exclusions = if reverse
                         Rsync.exclusions_from_container_to_host
                        else
                          Rsync.exclusions_from_host_to_container
                        end

  Rsync.exclusions + one_way_exclusions
end
normalize_options(source:, reverse: false, **) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 84
def normalize_options(source:, reverse: false, **)
  values = if source.include? APP_PATH
             ["#{APP_PATH}/", 'app']
           elsif GEMS_PATH.present? and source.include?(GEMS_PATH)
             ["#{GEMS_PATH}/", 'gems']
           else
             $stderr.puts "There is no rsync volume related with this path: #{source}"
             exit 1
           end

  paths = [values.first, "#{rsync_host}/#{values.last}"]

  [paths.send(reverse ? :reverse : :to_a), values.last].flatten
end
source_in_exclusions?(source:, reverse:, **) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 131
def source_in_exclusions?(source:, reverse:, **)
  !!all_exclusions(reverse: reverse).find do |e|
    source.include?("#{APP_PATH}/#{e}")
  end
end
sync_app(source:, target:, reverse:) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 99
      def sync_app(source:, target:, reverse:)
        exclusions = all_exclusions(reverse: reverse)

        system <<-EOS
        rsync -avqP --no-owner --no-group \
        #{exclusions.map{ |e| "--exclude '#{e}'" }.join(' '.freeze)} \
          --force \
          --delete \
          #{source} #{target}
        EOS
      end
sync_gems(source:, target:, **) click to toggle source
# File lib/docker_rails_proxy/concerns/rsync.rb, line 111
      def sync_gems(source:, target:, **)
        system <<-EOS
        rsync -avqP --no-owner --no-group \
          --exclude '.git*' \
          --force \
          --delete \
          #{source} #{target}
        EOS
      end