Class: Streetlib::Vault::Loader

Inherits:
Object
  • Object
show all
Includes:
Mu
Defined in:
lib/streetlib/vault/loader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Loader

Returns a new instance of Loader.



11
12
13
14
# File 'lib/streetlib/vault/loader.rb', line 11

def initialize(path:)
  self.path = path
  self.content = nil
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/streetlib/vault/loader.rb', line 9

def content
  @content
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/streetlib/vault/loader.rb', line 9

def path
  @path
end

Class Method Details

.load(path:) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/streetlib/vault/loader.rb', line 16

def self.load(path:)
  instance = new(path: path)
  result = instance.load
  return result if result.error?
    
  Result.success(instance)
end

Instance Method Details

#loadObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/streetlib/vault/loader.rb', line 24

def load
  context = { path: path }
  return Result.error(context).code!(:no_such_file) unless File.exists?(path)
    
  begin
    yaml_content = YAML.load_file(path)
  rescue StandardError => error
    return Result.
      error(context.merge({ error: error })).
      code!(:cant_load_file)
  end
    
  self.content = Content.new(yaml_content)
  Result.success
end