Sha256: bf568d74e8df2681db0f22e27db8536758ed315c0b202b0eb3db94ce5b1b5487

Contents?: true

Size: 570 Bytes

Versions: 2

Compression:

Stored size: 570 Bytes

Contents

require 'semantic'

module Elasticonf
  class Loader < Hashie::Mash
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elasticonf-1.1.5 lib/elasticonf/loader.rb
elasticonf-1.1.4 lib/elasticonf/loader.rb