Class: Hippo::YAMLPart
- Inherits:
-
Object
- Object
- Hippo::YAMLPart
- Defined in:
- lib/hippo/yaml_part.rb
Instance Attribute Summary collapse
-
#yaml ⇒ Object
readonly
Returns the value of attribute yaml.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #dig(*args) ⇒ Object
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(yaml, path, index) ⇒ YAMLPart
constructor
A new instance of YAMLPart.
- #parse(recipe, stage, commit) ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(yaml, path, index) ⇒ YAMLPart
Returns a new instance of YAMLPart.
7 8 9 10 11 |
# File 'lib/hippo/yaml_part.rb', line 7 def initialize(yaml, path, index) @yaml = yaml.strip @path = path @index = index end |
Instance Attribute Details
#yaml ⇒ Object (readonly)
Returns the value of attribute yaml.
5 6 7 |
# File 'lib/hippo/yaml_part.rb', line 5 def yaml @yaml end |
Instance Method Details
#[](name) ⇒ Object
34 35 36 |
# File 'lib/hippo/yaml_part.rb', line 34 def [](name) hash[name] end |
#[]=(name, value) ⇒ Object
38 39 40 |
# File 'lib/hippo/yaml_part.rb', line 38 def []=(name, value) hash[name] = value end |
#dig(*args) ⇒ Object
30 31 32 |
# File 'lib/hippo/yaml_part.rb', line 30 def dig(*args) hash.dig(*args) end |
#empty? ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/hippo/yaml_part.rb', line 19 def empty? @yaml.nil? || @yaml.empty? || hash.nil? || hash.empty? end |
#hash ⇒ Object
13 14 15 16 17 |
# File 'lib/hippo/yaml_part.rb', line 13 def hash @hash ||= YAML.safe_load(@yaml) rescue Psych::SyntaxError => e raise Error, "YAML parsing error in #{@path} (index #{@index}) (#{e.})" end |
#parse(recipe, stage, commit) ⇒ Object
42 43 44 45 |
# File 'lib/hippo/yaml_part.rb', line 42 def parse(recipe, stage, commit) parsed_part = recipe.parse(stage, commit, @yaml) self.class.new(parsed_part, @path, @index) end |
#to_yaml ⇒ Object
26 27 28 |
# File 'lib/hippo/yaml_part.rb', line 26 def to_yaml hash.to_yaml end |