Class: Elasticonf::Loader

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/elasticonf/loader.rb

Instance Method Summary collapse

Instance Method Details

#get(key) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/elasticonf/loader.rb', line 5

def get(key)
  unless [String, Symbol].include?(key.class)
    raise ArgumentError, "String or Symbol expected #{key.class} given"
  end

  ruby_version = Semantic::Version.new(RUBY_VERSION)

  if ruby_version.major == 2 && ruby_version.minor >= 3
    dig *key.split('.')
  else
    result, items = self.dup, key.split('.')

    while (item = items.shift)
      (result = result[item.to_sym]) || break
    end

    result
  end
end