class Guard::Fig

Constants

CONFIG_NAMES
VERSION

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/guard/fig.rb, line 10
def initialize(options = {})
  super(options)
  @config = load_config
  @fig = FigProxy.new(options)
end

Public Instance Methods

run_all() click to toggle source
# File lib/guard/fig.rb, line 26
def run_all
  @fig.up
end
run_on_changes(paths) click to toggle source
# File lib/guard/fig.rb, line 30
def run_on_changes(paths)
  debug paths.inspect

  if paths.any? { |x| x =~ Regexp.new(Regexp.escape(CONFIG_NAMES.join("|"))) }
    @fig.up
  else
    restart_services(paths)
  end
end
start() click to toggle source
# File lib/guard/fig.rb, line 16
def start
  boot2docker_setup if @options[:boot2docker_start]
  @fig.build if @options[:build_on_start]
  @fig.up recreate: false
end
stop() click to toggle source
# File lib/guard/fig.rb, line 22
def stop
  @fig.stop
end

Private Instance Methods

boot2docker_setup() click to toggle source
# File lib/guard/fig.rb, line 72
def boot2docker_setup
  system "boot2docker up"

  %x{boot2docker shellinit}.scan /export\s+(\S+)=(\S+)/ do |k, v|
    ENV[k] = v
  end
end
debug(msg) click to toggle source
# File lib/guard/fig.rb, line 80
def debug(msg)
  puts msg if ENV['DEBUG']
end
load_config() click to toggle source
# File lib/guard/fig.rb, line 84
def load_config
  config_file = CONFIG_NAMES.find do |file|
    File.exist?(file)
  end

  if config_file
    YAML.load_file(config_file)
  else
    puts "No file found with any name: #{CONFIG_NAMES.join(', ')}"
    exit 1
  end

end
restart_services(paths) click to toggle source
# File lib/guard/fig.rb, line 42
def restart_services(paths)
  directories = paths.flat_map { |p| p.split("/").first }.uniq
  services = []
  linked_services = []
  @config.each do |service, options|
    if directories.include? options['build']
      services << service
    end
  end
  @config.each do |service, options|
    debug "SERVICE: #{service}. Links #{options['links'].inspect}"
    if options['links'] && options['links'].any? { |l| services.include? l }
      linked_services << service
    end
  end
  debug services.inspect
  services.each do |service|
    @fig.stop service
    @fig.remove service
    @fig.build service
  end
  debug linked_services.inspect
  linked_services.uniq.each do |service|
    @fig.stop service
  end
  unless services.empty?
    @fig.up recreate: false
  end
end