class Renogen::ExtractionStratagies::YamlFile::Reader

Reads the relevant yaml files

Attributes

directory_path[RW]
legacy_version[RW]

Public Class Methods

new(directory_path, options = {}) click to toggle source
# 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

Public Instance Methods

each_yaml_file() { |content, i| ... } click to toggle source

Iterates thorugh each change file and yields the contents.

an exception is thrown if the contents are blank or invalid

@yield [Hash] yaml_file

# 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

Private Instance Methods

change_directories() click to toggle source

@return [Array]

# File lib/renogen/extraction_stratagies/yaml_file/reader.rb, line 39
def change_directories
  upgrade_versions = legacy_versions.map do |path|
    File.join(path, '*.yml')
  end
  upgrade_versions << File.join(directory_path, 'next', '*.yml')

  Dir.glob(upgrade_versions)
end
legacy_versions() click to toggle source

@return [Array]

# File lib/renogen/extraction_stratagies/yaml_file/reader.rb, line 49
def legacy_versions
  return [] unless legacy_version

  legacy_version.gsub!('v', '')
  Dir.glob(File.join(directory_path, '*')).select do |dir|
    dir = dir.split('/').last.gsub('v', '').gsub('_', '.')
    next if dir == 'next'

    Gem::Version.new(dir) > Gem::Version.new(legacy_version)
  end
end