Class: Dip::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dip/config.rb

Defined Under Namespace

Classes: ConfigFinder

Constant Summary collapse

DEFAULT_PATH =
"dip.yml"
CONFIG_DEFAULTS =
{
  environment: {},
  compose: {},
  kubectl: {},
  infra: {},
  interaction: {},
  provision: []
}.freeze
TOP_LEVEL_KEYS =
%i[environment compose kubectl infra interaction provision].freeze
ConfigKeyMissingError =
Class.new(ArgumentError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work_dir = Dir.pwd) ⇒ Config

Returns a new instance of Config.



89
90
91
# File 'lib/dip/config.rb', line 89

def initialize(work_dir = Dir.pwd)
  @work_dir = work_dir
end

Class Method Details

.load_yaml(file_path = path) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dip/config.rb', line 70

def load_yaml(file_path = path)
  return {} unless File.exist?(file_path)

  data = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("4.0.0")
    YAML.safe_load(
      ERB.new(File.read(file_path)).result,
      aliases: true
    )
  else
    YAML.safe_load(
      ERB.new(File.read(file_path)).result,
      [], [], true
    )
  end

  data&.deep_symbolize_keys! || {}
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/dip/config.rb', line 101

def exist?
  finder.exist?
end

#file_pathObject



93
94
95
# File 'lib/dip/config.rb', line 93

def file_path
  finder.file_path
end

#module_file(filename) ⇒ Object



97
98
99
# File 'lib/dip/config.rb', line 97

def module_file(filename)
  finder.modules_dir / "#{filename}.yml"
end

#to_hObject



105
106
107
# File 'lib/dip/config.rb', line 105

def to_h
  config
end