class FigRake::Configuration

Constants

COMPOSE_FILE
FIG_FILE

Attributes

container_name[RW]
docker_command[RW]
rake_args[RW]

Public Class Methods

new(name: nil, command: nil) click to toggle source
# File lib/fig_rake/configuration.rb, line 10
def initialize(name: nil, command: nil)
  @container_name = name || name_from_defaults
  @docker_command = command || command_from_defaults
end

Public Instance Methods

command_from_defaults() click to toggle source
# File lib/fig_rake/configuration.rb, line 19
def command_from_defaults
  command_from_environment || command_from_file
end
command_from_environment() click to toggle source
# File lib/fig_rake/configuration.rb, line 27
def command_from_environment
  ENV['FIG_RAKE_COMMAND']
end
command_from_file() click to toggle source
# File lib/fig_rake/configuration.rb, line 39
def command_from_file
  case
  when compose_file_exists?
    "docker-compose"
  when fig_file_exists?
    "fig"
  else
    raise "No configuration file found are you in the right Directory?"
  end
end
compose_file_exists?() click to toggle source
# File lib/fig_rake/configuration.rb, line 31
def compose_file_exists?
  File.exists? COMPOSE_FILE
end
fig_file_exists?() click to toggle source
# File lib/fig_rake/configuration.rb, line 35
def fig_file_exists?
  File.exists? FIG_FILE
end
name_from_defaults() click to toggle source
# File lib/fig_rake/configuration.rb, line 15
def name_from_defaults
  name_from_environment || name_from_file
end
name_from_environment() click to toggle source
# File lib/fig_rake/configuration.rb, line 23
def name_from_environment
  ENV['FIG_RAKE_CONTAINER']
end
name_from_file() click to toggle source
# File lib/fig_rake/configuration.rb, line 50
def name_from_file
  file_name = case
              when compose_file_exists?
                COMPOSE_FILE
              when fig_file_exists?
                FIG_FILE
              else
                raise "No configuration file found are you in the right Directory?"
              end
  
  container_config = YAML.load(File.read(file_name)).to_a.select do |(_, opts)|
    opts.has_key?("build")
  end
  container_config.first.first
end