Class: YamlRefResolver::Yaml

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml_ref_resolver/yaml.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, content, key) ⇒ Yaml

Returns a new instance of Yaml.



18
19
20
21
22
# File 'lib/yaml_ref_resolver/yaml.rb', line 18

def initialize(path, content, key)
  @filepath = path
  @content = content
  @key = key
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/yaml_ref_resolver/yaml.rb', line 4

def content
  @content
end

Class Method Details

.load!(path:, key: '$ref') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/yaml_ref_resolver/yaml.rb', line 6

def self.load!(path:, key: '$ref')
  if File.exist?(path)
    begin
      self.new(path, YAML.load_file(path), key)
    rescue Psych::SyntaxError => e
      raise YamlRefResolver::YamlSyntaxErrorException.new(exception: e)
    end
  else
    raise YamlRefResolver::YamlNotFoundException.new(path: path)
  end
end

Instance Method Details

#refsObject



24
25
26
27
28
# File 'lib/yaml_ref_resolver/yaml.rb', line 24

def refs
  find_refs(@content).flatten.compact.map do |ref|
    YamlRefResolver::Ref.new(ref, @filepath)
  end
end