Class: LoadFile::Loader

Inherits:
Hash
  • Object
show all
Defined in:
lib/load_file/loader.rb

Overview

A class to load `file` into Hash, find or create constant by `constant_name`.

Returns:

  • (Hash)

    parsed YAML or JSON content

Instance Method Summary collapse

Constructor Details

#initialize(file, constant_name, namespace: Object) ⇒ Loader

Returns a new instance of Loader



9
10
11
12
13
14
15
# File 'lib/load_file/loader.rb', line 9

def initialize(file, constant_name, namespace: Object)
  @file = file
  @namespace = namespace
  @constant = find_or_define(constant_name)

  update parsed_content
end

Instance Method Details

#set_constantObject

Set `values` into `constant` if not exists.



18
19
20
# File 'lib/load_file/loader.rb', line 18

def set_constant
  each { |key, value| constant[key] ||= value }
end

#set_constant!Object

Override `values` into `constant`.



23
24
25
# File 'lib/load_file/loader.rb', line 23

def set_constant!
  each { |key, value| constant[key] = value }
end