class Confuse::KeySplitter
This class encapsulates the code required to support searching for items with a single key item even for nested items. config instead of config[:bar]
Public Class Methods
new(key)
click to toggle source
# File lib/confuse/key_splitter.rb, line 8 def initialize(key) @key = key end
Public Instance Methods
possible_namespaces()
click to toggle source
Returns an array of possible namespaces based on splitting the key at every underscore.
# File lib/confuse/key_splitter.rb, line 20 def possible_namespaces namespaces = [] key = @key.to_s while (index = key.rindex('_')) key = key[0, index] namespaces << key.to_sym end namespaces end
rest_of_key(namespace)
click to toggle source
Returns the rest of the key for a given namespace
# File lib/confuse/key_splitter.rb, line 31 def rest_of_key(namespace) return nil if @key == namespace key = @key.to_s index = key.index(namespace.to_s) && (namespace.to_s.length + 1) key[index, key.length].to_sym if index end
split()
click to toggle source
# File lib/confuse/key_splitter.rb, line 12 def split possible_namespaces.map do |ns| [ns, rest_of_key(ns)] end end