Class: S3Light::Client::BucketsList
- Inherits:
-
Object
- Object
- S3Light::Client::BucketsList
- Defined in:
- lib/s3-light/client/buckets_list.rb
Instance Method Summary collapse
- #all ⇒ Object
- #create_batch(names:, concurrency: 10) ⇒ Object
- #destroy_batch(names:, concurrency: 10) ⇒ Object
- #exists?(name:) ⇒ Boolean
- #exists_batch?(names:, concurrency: 10) ⇒ Boolean
- #find_by(name:) ⇒ Object
-
#initialize(client) ⇒ BucketsList
constructor
A new instance of BucketsList.
- #inspect ⇒ Object
- #new(name: nil) ⇒ Object
Constructor Details
#initialize(client) ⇒ BucketsList
Returns a new instance of BucketsList.
6 7 8 |
# File 'lib/s3-light/client/buckets_list.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/s3-light/client/buckets_list.rb', line 10 def all response = @client.with_connection do |connection| connection.make_request(:get, '/') end response.xml.remove_namespaces!.xpath('//Bucket').map do |bucket| S3Light::Bucket.new(@client, bucket.xpath('Name').text, true) end end |
#create_batch(names:, concurrency: 10) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/s3-light/client/buckets_list.rb', line 28 def create_batch(names:, concurrency: 10) result = ConcurrentResult.new thread_poll = @client.build_thread_poll(concurrency) current_thread = Thread.current names.each do |name| thread_poll.with_connection do |connection| bucket = S3Light::Bucket.new(@client, name, true) bucket.__save!(connection) result.add(name, bucket) rescue Exception => e thread_poll.kill current_thread.raise(e) end end thread_poll.wait_to_finish result.to_h ensure thread_poll.close end |
#destroy_batch(names:, concurrency: 10) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/s3-light/client/buckets_list.rb', line 52 def destroy_batch(names:, concurrency: 10) result = ConcurrentResult.new thread_poll = @client.build_thread_poll(concurrency) current_thread = Thread.current names.each do |name| thread_poll.with_connection do |connection| new(name: name).__destroy!(connection) result.add(name, true) rescue Exception => e thread_poll.kill current_thread.raise(e) end end thread_poll.wait_to_finish result.to_h ensure thread_poll.close end |
#exists?(name:) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/s3-light/client/buckets_list.rb', line 20 def exists?(name:) response = @client.with_connection do |connection| connection.make_request(:head, "/#{name}") end response.code == 200 end |
#exists_batch?(names:, concurrency: 10) ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/s3-light/client/buckets_list.rb', line 75 def exists_batch?(names:, concurrency: 10) result = ConcurrentResult.new thread_poll = @client.build_thread_poll(concurrency) current_thread = Thread.current names.each do |name| thread_poll.with_connection do |connection| result.add(name, connection.make_request(:head, "/#{name}")) end rescue Exception => e thread_poll.kill current_thread.raise(e) end thread_poll.wait_to_finish result.to_h ensure thread_poll.close end |
#find_by(name:) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/s3-light/client/buckets_list.rb', line 96 def find_by(name:) @client.with_connection do |connection| connection.make_request(:get, "/#{name}") end S3Light::Bucket.new(@client, name, true) rescue S3Light::Connection::HttpError => e return nil if e.code == 404 raise e end |
#inspect ⇒ Object
113 114 115 |
# File 'lib/s3-light/client/buckets_list.rb', line 113 def inspect "#<#{self.class.name} @buckets=#{all.size}>" end |