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: {},
  interation: {},
  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.


81
82
83
# File 'lib/dip/config.rb', line 81

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

Class Method Details

.load_yaml(file_path = path) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dip/config.rb', line 62

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)

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

def exist?
  finder.exist?
end

#file_pathObject


85
86
87
# File 'lib/dip/config.rb', line 85

def file_path
  finder.file_path
end

#to_hObject


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

def to_h
  config
end