Method: Filigree::Commands::ClassMethods#reify_namespace

Defined in:
lib/filigree/commands.rb

#reify_namespace(tokens, root: @commands) ⇒ Array<(Hash<Symbol, Hash>, Array<String>)>

Find or create the namespace specified by tokens.

Parameters:

  • tokens (Array<String>)

    Tokens specifying the namespace.

  • root (Hash<Symbol, Hash>) (defaults to: @commands)

    Root namespace

Returns:

  • (Array<(Hash<Symbol, Hash>, Array<String>)>)

    The requested namespace and the remainder of the tokens.



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/filigree/commands.rb', line 184

def reify_namespace(tokens, root: @commands)
  if tokens.empty?
    root
  else
    curr_token = tokens.shift
  
    ns = root[curr_token]
    ns = root[curr_token] = Hash.new if ns.nil?
  
    reify_namespace(tokens, root: ns)
  end
end