Class: RVGP::Utilities::Yaml
- Inherits:
-
Object
- Object
- RVGP::Utilities::Yaml
- Defined in:
- lib/rvgp/utilities/yaml.rb
Overview
This class wraps the Psych library, and adds functionality we need, to parse yaml files. We mostly added this class because the Psych.add_builtin_type wasn’t able to contain state outside it’s return values. (which we need, in order to track include dependencies)
Defined Under Namespace
Classes: PsychInclude, PsychProc
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#include_paths ⇒ Object
readonly
Returns the value of attribute include_paths.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#[](attr) ⇒ Object
Return the specified attribute, in this yaml file.
-
#initialize(path, include_paths = nil) ⇒ Yaml
constructor
A new instance of Yaml.
-
#key?(attr) ⇒ TrueClass, FalseClass
(also: #has_key?)
Returns true or false, depending on whether the attribute you’re looking for, exists in this yaml file.
Constructor Details
#initialize(path, include_paths = nil) ⇒ Yaml
Returns a new instance of Yaml.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rvgp/utilities/yaml.rb', line 87 def initialize(path, include_paths = nil) @path = path @dependencies = [] @include_paths = Array(include_paths || File.(File.dirname(path))) vanilla_yaml = Psych.safe_load_file(path, symbolize_names: true, permitted_classes: [Date, Symbol]) @yaml = replace_each_in_yaml(vanilla_yaml, PsychInclude) do |psych_inc| @dependencies << psych_inc.path psych_inc.contents @include_paths end end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
82 83 84 |
# File 'lib/rvgp/utilities/yaml.rb', line 82 def dependencies @dependencies end |
#include_paths ⇒ Object (readonly)
Returns the value of attribute include_paths.
82 83 84 |
# File 'lib/rvgp/utilities/yaml.rb', line 82 def include_paths @include_paths end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
82 83 84 |
# File 'lib/rvgp/utilities/yaml.rb', line 82 def path @path end |
Instance Method Details
#[](attr) ⇒ Object
Return the specified attribute, in this yaml file
102 103 104 |
# File 'lib/rvgp/utilities/yaml.rb', line 102 def [](attr) @yaml&.[](attr) end |
#key?(attr) ⇒ TrueClass, FalseClass Also known as: has_key?
Returns true or false, depending on whether the attribute you’re looking for, exists in this yaml file.
110 111 112 |
# File 'lib/rvgp/utilities/yaml.rb', line 110 def key?(attr) @yaml&.key? attr end |