Class: Nerv

Inherits:
Object
  • Object
show all
Defined in:
lib/nerv.rb,
lib/nerv/version.rb

Constant Summary collapse

DEFAULT_SEPARATOR =
'_'.freeze
VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.[](keys_prefix) ⇒ Object



17
18
19
# File 'lib/nerv.rb', line 17

def [](keys_prefix)
  prefix(keys_prefix)
end

.prefix(keys_prefix, separator = DEFAULT_SEPARATOR) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/nerv.rb', line 7

def prefix(keys_prefix, separator = DEFAULT_SEPARATOR)
  regexp = /^#{keys_prefix}#{separator}/

  pairs = ENV.map { |k, v| [k.gsub(regexp, ''), v] if k =~ regexp }
             .compact
             .flatten

  Hash[*pairs]
end