Class: Egg::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/egg/configuration.rb

Overview

Reads and Processes the egg_config.rb file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&configuration_block) ⇒ Configuration

Returns a new instance of Configuration.



29
30
31
32
33
34
# File 'lib/egg/configuration.rb', line 29

def initialize(&configuration_block)
  self.ssh_support = false
  self.dotenv = DotenvUtil.new(File.read(".env.template")) if File.exist?(".env.template")
  instance_eval(&configuration_block)
  self
end

Instance Attribute Details

#dotenvObject

Returns the value of attribute dotenv.



25
26
27
# File 'lib/egg/configuration.rb', line 25

def dotenv
  @dotenv
end

#ssh_supportObject

Returns the value of attribute ssh_support.



25
26
27
# File 'lib/egg/configuration.rb', line 25

def ssh_support
  @ssh_support
end

#supervisorObject

Returns the value of attribute supervisor.



25
26
27
# File 'lib/egg/configuration.rb', line 25

def supervisor
  @supervisor
end

Class Method Details

.load(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/egg/configuration.rb', line 13

def self.load(file)
  code = File.read file
  config = eval code, binding, file # rubocop:disable Security/Eval

  return config if config.is_a? Egg::Configuration
rescue SignalException, SystemExit
  raise
rescue SyntaxError, StandardError => e
  warn "Invalid configuration in [#{file}]: #{e}"
  warn e.backtrace.join("\n")
end

Instance Method Details

#after_startup(&block) ⇒ Object



36
37
38
# File 'lib/egg/configuration.rb', line 36

def after_startup(&block)
  @after_startup = block
end

#docker_exec(app, command) ⇒ Object

You may pass a block to docker_exec to read the output in a controlled manner.



41
42
43
44
45
46
47
48
49
# File 'lib/egg/configuration.rb', line 41

def docker_exec(app, command)
  print "docker-compose exec #{app} #{command}\n"
  Open3.popen2(%(docker-compose exec #{app} #{command})) do |_input, output, wait_thread|
    output_read = output.read
    print output_read + "\n"
    yield output_read if block_given?
    wait_thread.value.success? || raise(StandardError, "docker_exec exited with #{wait_thread.value.to_i}")
  end
end

#docker_pull_buildObject



67
68
69
70
# File 'lib/egg/configuration.rb', line 67

def docker_pull_build
  system("docker-compose pull")
  system("docker-compose build") || raise($CHILD_STATUS)
end

#docker_run(app, command) ⇒ Object

You may pass a block to docker_run to read the output in a controlled manner.



52
53
54
55
56
57
58
59
60
# File 'lib/egg/configuration.rb', line 52

def docker_run(app, command)
  print "docker-compose run #{app} #{command}\n"
  Open3.popen2(%(docker-compose run #{app} #{command})) do |_input, output, wait_thread|
    output_read = output.read
    print output_read + "\n"
    yield output_read if block_given?
    wait_thread.value.success? || raise(StandardError, "docker_run exited with #{wait_thread.value.to_i}")
  end
end

#run_setupObject



62
63
64
65
# File 'lib/egg/configuration.rb', line 62

def run_setup
  docker_pull_build
  run_after_startup
end