Module: Luban::Deployment::Helpers::Configuration

Included in:
Command, Runner, Worker::Base
Defined in:
lib/luban/deployment/helpers/configuration.rb

Defined Under Namespace

Classes: Finder

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/luban/deployment/helpers/configuration.rb', line 5

def config
  @config
end

Instance Method Details

#ask(key = nil, default: nil, prompt: nil, echo: true) ⇒ Object



23
24
25
# 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) ⇒ Object



11
12
13
# 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) ⇒ Object

Raises:

  • (RuntimeError)


71
72
73
74
75
76
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# 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) ⇒ Object



43
44
45
# File 'lib/luban/deployment/helpers/configuration.rb', line 43

def primary(role)
  config.primary(role)
end

#release_roles(*names) ⇒ Object



39
40
41
# File 'lib/luban/deployment/helpers/configuration.rb', line 39

def release_roles(*names)
  config.release_roles(*names)
end

#role(name, hosts, **properties) ⇒ Object



27
28
29
# 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) ⇒ Object



35
36
37
# File 'lib/luban/deployment/helpers/configuration.rb', line 35

def roles(*names)
  config.roles(*names)
end

#server(name, **properties) ⇒ Object



31
32
33
# 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) ⇒ Object



15
16
17
# 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) ⇒ Object



19
20
21
# 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) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
# 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