class RakeTasksDockerSync::Services

Public Class Methods

from_args(_args) click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 6
def self.from_args(_args)
  raise 'No docker-sync.yml configuration found in your path' unless File.exist?('docker-sync.yml')

  docker_sync_config = YAML.load_file('docker-sync.yml')

  self.new(docker_sync_config['syncs'].keys)
end
new(syncs) click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 14
def initialize(syncs)
  @services = syncs
end

Public Instance Methods

down() click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 30
def down
  execute do
    system 'docker-sync', 'clean'
  end
end
exec(user, command) click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 36
def exec(user, command)
  @services.each do |service|
    execute do
      system 'docker', 'exec', '--user', user, service, command
    end
  end
end
stop() click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 24
def stop
  execute do
    system 'docker-sync', 'stop'
  end
end
up() click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 18
def up
  execute do
    system 'docker-sync', 'start'
  end
end

Protected Instance Methods

containers() click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 56
def containers
  `#{@services.map { |service| "docker ps -q -f 'name=#{service}'" }.join(' && ')}`.split("\n")
end
execute() { |block| ... } click to toggle source
# File lib/rake-tasks-docker-sync/services.rb, line 46
def execute(&block)
  if defined?(Bundler)
    Bundler.with_clean_env do
      yield block
    end
  else
    yield block
  end
end