Class: InteractiveS3::S3Path

Inherits:
Object
  • Object
show all
Defined in:
lib/interactive_s3/s3_path.rb

Instance Method Summary collapse

Constructor Details

#initialize(target_path, current_stack) ⇒ S3Path

Returns a new instance of S3Path.



5
6
7
8
# File 'lib/interactive_s3/s3_path.rb', line 5

def initialize(target_path, current_stack)
  @target_path = target_path
  @current_stack = current_stack
end

Instance Method Details

#resolveObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/interactive_s3/s3_path.rb', line 10

def resolve
  stack = current_stack.dup

  begin
    bol = scanner.bol?
    segment = scanner.scan(/[^\/]*/)
    scanner.getch

    case segment.chomp
    when ''
      stack = [] if bol
    when '.'
      next
    when '..'
      stack.pop
    else
      stack << segment
    end
  rescue => e
    raise CommandError.new(e).tap {|ex|
      ex.set_backtrace(e.backtrace)
    }
  end until scanner.eos?

  stack
end