Class: Streetlib::Vault::Loader
- Inherits:
-
Object
- Object
- Streetlib::Vault::Loader
- Includes:
- Mu
- Defined in:
- lib/streetlib/vault/loader.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path:) ⇒ Loader
constructor
A new instance of Loader.
- #load ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'lib/streetlib/vault/loader.rb', line 9 def content @content end |
#path ⇒ Object
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
#load ⇒ Object
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 |