class BRocket::Configurable

Constants

CONFIG_LINE_HEADER
CONFIG_LINE_SEP

Public Instance Methods

config_filepath() click to toggle source
# File lib/brocket/configurable.rb, line 39
def config_filepath
  @config_filepath ||= File.expand_path(options[:dockerfile] || './Dockerfile', BRocket.user_pwd)
end
config_hash() click to toggle source
# File lib/brocket/configurable.rb, line 28
def config_hash
  @config_hash ||= load_config_hash
end
config_image_name() click to toggle source
# File lib/brocket/configurable.rb, line 17
def config_image_name
  img_name = (config_hash['IMAGE_NAME'] || '').strip
  error "No IMAGE_NAME found in Dockerfile. Please add `# #{CONFIG_LINE_SEP} IMAGE_NAME: [IMAGE NAME on DockerHub]` in Dockerfile" if img_name.empty?
  img_name
end
config_relpath() click to toggle source
# File lib/brocket/configurable.rb, line 43
def config_relpath
  config_p = Pathname.new(config_filepath)
  base_p   = Pathname.new(working_dir)
  config_p.relative_path_from(base_p).to_s
end
load_config_hash() click to toggle source
# File lib/brocket/configurable.rb, line 32
def load_config_hash
  content = read_config_file
  lines = content.lines.select{|line| line =~ CONFIG_LINE_HEADER}.
    map{|line| line.sub(CONFIG_LINE_HEADER, "")}
  return (YAML.load(lines.join("\n")) || {})
end
read_config_file() click to toggle source
# File lib/brocket/configurable.rb, line 49
def read_config_file
  unless File.readable?(config_filepath)
    error "File not found: #{config_filepath}"
  end
  File.read(config_filepath)
end
working_dir() click to toggle source
# File lib/brocket/configurable.rb, line 23
def working_dir
  dir = config_hash['WORKING_DIR'] || '.'
  File.expand_path(dir, File.dirname(config_filepath))
end