Class: InteractiveS3::S3

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeS3

Returns a new instance of S3.



7
8
9
# File 'lib/interactive_s3/s3.rb', line 7

def initialize
  @stack = []
end

Instance Attribute Details

#stackObject

Returns the value of attribute stack.



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

def stack
  @stack
end

Instance Method Details

#bucket?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/interactive_s3/s3.rb', line 24

def bucket?
  stack.size == 1
end

#current_pathObject



11
12
13
# File 'lib/interactive_s3/s3.rb', line 11

def current_path
  empty? ? '' : "s3://#{stack.join('/')}"
end

#empty?Boolean Also known as: root?

Returns:

  • (Boolean)


15
16
17
# File 'lib/interactive_s3/s3.rb', line 15

def empty?
  stack.empty?
end

#exists?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/interactive_s3/s3.rb', line 28

def exists?
  return true if root?
  output, error, status = Open3.capture3('aws', 's3', 'ls', current_path)
  status.success? && (bucket? || (output != '' && output.match(/(\S*)\/$/)[1] == stack.last))
end

#resetObject



20
21
22
# File 'lib/interactive_s3/s3.rb', line 20

def reset
  self.stack = []
end