Class: Hippo::YAMLPart

Inherits:
Object
  • Object
show all
Defined in:
lib/hippo/yaml_part.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#yamlObject (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

Returns:

  • (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

#hashObject



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.message})"
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_yamlObject



26
27
28
# File 'lib/hippo/yaml_part.rb', line 26

def to_yaml
  hash.to_yaml
end