Class: Gimlet::DataStore
- Inherits:
-
Object
- Object
- Gimlet::DataStore
- Extended by:
- Forwardable
- Defined in:
- lib/gimlet/data_store.rb
Instance Method Summary collapse
-
#initialize(data_directory) ⇒ DataStore
constructor
A new instance of DataStore.
- #load_all! ⇒ Object
Constructor Details
#initialize(data_directory) ⇒ DataStore
Returns a new instance of DataStore.
10 11 12 13 14 |
# File 'lib/gimlet/data_store.rb', line 10 def initialize(data_directory) @data_directory = Pathname(data_directory) @local_data = ::Gimlet::Util.recursively_enhance({}) load_all! end |
Instance Method Details
#load_all! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gimlet/data_store.rb', line 16 def load_all! Pathname.glob(@data_directory + '**/*.{yaml,yml}').each do |path| extension = path.extname basename = path.basename(extension) parts = path.relative_path_from(@data_directory).split.map(&:to_s)[0..-1] parts.delete('.') parts.pop current = @local_data parts.each do |part| current[part] ||= ::Gimlet::Util.recursively_enhance({}) current = current[part] end current[basename.to_s] = ::Gimlet::Util.recursively_enhance(YAML.load_file(path)) end end |