module Luban::Deployment::Helpers::Configuration

Attributes

config[RW]

Public Instance Methods

ask(key=nil, default: nil, prompt: nil, echo: true) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 23
def ask(key=nil, default: nil, prompt: nil, echo: true)
  config.ask(key, default: default, echo: echo, prompt: prompt)
end
fetch(key, *args, &blk) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 11
def fetch(key, *args, &blk)
  config.fetch(key, *args, &blk)
end
find_template_file(file_name) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 71
def find_template_file(file_name)
  path = find_template_file_by_config_finder(file_name) ||
         Finder.find_default_template_file(file_name)
  raise RuntimeError, "Template file is NOT found: #{file_name}." if path.nil?
  path
end
load_configuration_file(config_file, optional: false) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 47
def load_configuration_file(config_file, optional: false)
  if File.file?(config_file)
    if error = syntax_error?(config_file)
      abort "Aborted! Syntax errors in configuration file.\n#{error}"
    else
      instance_eval(File.read(config_file))
    end
  else
    unless optional
      abort "Aborted! Configuration file is NOT found: #{config_file}"
    end
  end
end
primary(role) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 43
def primary(role)
  config.primary(role)
end
release_roles(*names) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 39
def release_roles(*names)
  config.release_roles(*names)
end
role(name, hosts, **properties) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 27
def role(name, hosts, **properties)
  config.role(name, hosts, properties.merge(local: dockerized?))
end
roles(*names) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 35
def roles(*names)
  config.roles(*names)
end
server(name, **properties) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 31
def server(name, **properties)
  config.server(name, properties.merge(local: dockerized?))
end
set(key, *args, &blk) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 15
def set(key, *args, &blk)
  config.set(key, *args, &blk)
end
set_default(key, *args, &blk) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 19
def set_default(key, *args, &blk)
  config.set_default(key, *args, &blk)
end
syntax_error?(file) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 61
def syntax_error?(file)
  _stderr = $stderr
  $stderr = StringIO.new('', 'w')
  # ONLY work for MRI Ruby
  RubyVM::InstructionSequence.compile_file(file)
  $stderr.string.chomp.empty? ? false : $stderr.string
ensure
  $stderr = _stderr
end

Protected Instance Methods

find_template_file_by_config_finder(file_name) click to toggle source
# File lib/luban/deployment/helpers/configuration.rb, line 80
def find_template_file_by_config_finder(file_name)
  path = config_finder[:application].find_template_file(file_name) ||
         config_finder[:project].find_template_file(file_name)
end