Class: Mayl::Commands::Cd

Inherits:
Object
  • Object
show all
Defined in:
lib/mayl/commands/cd.rb

Overview

Public: The Cd command navigates through YAML namespaces.

Example

command = Cd.new(env, 'models.bla')
command.execute

Instance Method Summary collapse

Constructor Details

#initialize(env, path) ⇒ Cd

Public: Initializes a new Cd command.

env - the global environment path - the path to cd in



15
16
17
18
# File 'lib/mayl/commands/cd.rb', line 15

def initialize(env, path)
  @env  = env
  @path = path
end

Instance Method Details

#executeObject

Public: Adds the path to the namespace.

Returns nil.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mayl/commands/cd.rb', line 23

def execute
  case @path
  when ".."
    ns = @env.namespace.split('.')
    ns.pop
    @env.namespace = ns.join('.')
  when "."
    @env.namespace = ""
  else
    if @env.namespace.empty?
      @env.namespace = @path
    else
      @env.namespace += '.' << @path
    end
  end
  nil
end