lib/mayl/commands/cd.rb in mayl-0.2.0 vs lib/mayl/commands/cd.rb in mayl-0.2.1
- old
+ new
@@ -20,29 +20,35 @@
# Public: Adds the path to the namespace.
#
# Returns nil.
def execute
+ namespace = @env.namespace
+
case @path
when ".."
- ns = @env.namespace.split('.')
+ ns = namespace.split('.')
ns.pop
@env.namespace = ns.join('.')
when "."
@env.namespace = ""
else
check_namespace!
- if @env.namespace.empty?
+ if namespace.empty?
@env.namespace = @path
else
@env.namespace += '.' << @path
end
end
nil
end
- # Public: Checks that you're not trying to enter a leaf.
+ #######
+ private
+ #######
+
+ # Internal: Checks that you're not trying to enter a leaf.
#
# Raises an ArgumentError if you are.
def check_namespace!
namespace = [@env.namespace, @path].reject(&:empty?).join('.')
matches = @env.peek(namespace).compact