Class: Natives::Catalog::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/natives/catalog/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Loader

Returns a new instance of Loader.



8
9
10
# File 'lib/natives/catalog/loader.rb', line 8

def initialize(opts={})
  @merger = opts.fetch(:merger, Merger.new)
end

Instance Method Details

#load_from_paths(paths) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/natives/catalog/loader.rb', line 12

def load_from_paths(paths)
  master_hash = {}
  Array(paths).each do |path|
    yaml_files_in_path(path).sort.each do |file|
      @merger.merge_catalog!(master_hash, load_yaml_file(file))
    end
  end
  master_hash
end

#load_yaml_file(filename) ⇒ Object



26
27
28
# File 'lib/natives/catalog/loader.rb', line 26

def load_yaml_file(filename)
  YAML.load_file(filename)
end

#yaml_files_in_path(path) ⇒ Object



22
23
24
# File 'lib/natives/catalog/loader.rb', line 22

def yaml_files_in_path(path)
  Dir.glob(File.join(path, '*.{yml,yaml}'))
end