Sha256: 4382d895fcc0364cc064057e68647f959b9d98556de0c8908c5372f7c8830069

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

module Mayl
  module Commands
    # Public: The Cd command navigates through YAML namespaces.
    #
    # Example
    # 
    #   command = Cd.new(env, 'models.bla')
    #   command.execute
    #
    class Cd
      # Public: Initializes a new Cd command.
      #
      # env  - the global environment
      # path - the path to cd in
      def initialize(env, path)
        @env  = env
        @path = path
      end

      # Public: Adds the path to the namespace.
      #
      # Returns nil.
      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mayl-0.1.0 lib/mayl/commands/cd.rb
mayl-0.0.1 lib/mayl/commands/cd.rb