Class: CIDE::ConfigFile

Inherits:
Object
  • Object
show all
Includes:
NiceInspect
Defined in:
lib/cide/config_file.rb

Defined Under Namespace

Modules: NiceInspect Classes: FileAdd, Link, Step

Constant Summary collapse

DOCKERFILE_TEMPLATE =
File.expand_path('../dockerfile_template.erb', __FILE__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NiceInspect

#inspect

Constructor Details

#initializeConfigFile

Returns a new instance of ConfigFile.



62
63
64
65
66
# File 'lib/cide/config_file.rb', line 62

def initialize(*)
  super
  @warnings = []
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



60
61
62
# File 'lib/cide/config_file.rb', line 60

def errors
  @errors
end

#warningsObject (readonly)

Returns the value of attribute warnings.



60
61
62
# File 'lib/cide/config_file.rb', line 60

def warnings
  @warnings
end

Class Method Details

.find_config(dir) ⇒ Object



94
95
96
97
98
99
# File 'lib/cide/config_file.rb', line 94

def self.find_config(dir)
  paths = CONFIG_FILES.map { |name| File.expand_path(name, dir) }
  paths
    .find { |path| File.exist?(path) } ||
    fail("Config not found among these paths: #{paths.inspect}")
end

.load(dir, output = $stderr) ⇒ Object



72
73
74
75
# File 'lib/cide/config_file.rb', line 72

def self.load(dir, output = $stderr)
  file_path = find_config(dir)
  load_file(file_path, output)
end

.load_file(file_path, output = $stderr) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cide/config_file.rb', line 77

def self.load_file(file_path, output = $stderr)
  obj = new
  loader = ConfigFileLoader.new(obj)
  loader.load YAML.load_file(file_path)

  obj.warnings.each do |warn|
    output.puts "WARN: #{warn}"
  end

  obj.errors.each do |error|
    output.puts "ERROR: #{error}"
  end

  return obj if obj.errors.empty?
  nil
end

Instance Method Details

#to_dockerfileObject



68
69
70
# File 'lib/cide/config_file.rb', line 68

def to_dockerfile
  ERB.new(File.read(DOCKERFILE_TEMPLATE), nil, '<>-').result(binding)
end