Class: Renogen::ExtractionStratagies::YamlFile::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/renogen/extraction_stratagies/yaml_file/reader.rb

Overview

Reads the relevant yaml files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory_path, options = {}) ⇒ Reader

Returns a new instance of Reader.



12
13
14
15
16
# File 'lib/renogen/extraction_stratagies/yaml_file/reader.rb', line 12

def initialize(directory_path, options = {})
  @legacy_version = options['legacy_version']
  @directory_path = directory_path
  @directory_path ||= './change_log/'
end

Instance Attribute Details

#directory_pathObject

Returns the value of attribute directory_path.



10
11
12
# File 'lib/renogen/extraction_stratagies/yaml_file/reader.rb', line 10

def directory_path
  @directory_path
end

#legacy_versionObject

Returns the value of attribute legacy_version.



10
11
12
# File 'lib/renogen/extraction_stratagies/yaml_file/reader.rb', line 10

def legacy_version
  @legacy_version
end

Instance Method Details

#each_yaml_file {|Hash| ... } ⇒ Object

Iterates thorugh each change file and yields the contents.

an exception is thrown if the contents are blank or invalid

Yields:

  • (Hash)

    yaml_file



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/renogen/extraction_stratagies/yaml_file/reader.rb', line 23

def each_yaml_file
  path = ''
  change_directories.each_with_index do |file_path, i|
    path = file_path
    content = ::YAML.load_file(file_path)
    raise Exceptions::YamlFileBlank, file_path unless content

    yield content, i
  end
rescue Psych::SyntaxError
  raise Exceptions::YamlFileInvalid, path
end