Class: BosClient::Bucket
- Inherits:
-
Object
- Object
- BosClient::Bucket
- Defined in:
- lib/bos_client/bucket.rb
Instance Attribute Summary collapse
-
#bucket_host ⇒ Object
Returns the value of attribute bucket_host.
-
#creation_date ⇒ Object
Returns the value of attribute creation_date.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #accessable? ⇒ Boolean
- #destory ⇒ Object
- #dir_objects(prefix, options = {}) ⇒ Object
- #dirs(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Bucket
constructor
A new instance of Bucket.
-
#objects(options = {}) ⇒ Object
objects.
- #save ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Bucket
Returns a new instance of Bucket.
6 7 8 9 10 11 |
# File 'lib/bos_client/bucket.rb', line 6 def initialize( = {}) @name = [:name] @location = [:location] || BosClient.location @creation_date = [:creation_date] @bucket_host = "#{BosClient.scheme}://#{@name}.#{@location}.#{BosClient.url}" end |
Instance Attribute Details
#bucket_host ⇒ Object
Returns the value of attribute bucket_host.
4 5 6 |
# File 'lib/bos_client/bucket.rb', line 4 def bucket_host @bucket_host end |
#creation_date ⇒ Object
Returns the value of attribute creation_date.
4 5 6 |
# File 'lib/bos_client/bucket.rb', line 4 def creation_date @creation_date end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/bos_client/bucket.rb', line 4 def name @name end |
Instance Method Details
#accessable? ⇒ Boolean
13 14 15 16 17 |
# File 'lib/bos_client/bucket.rb', line 13 def accessable? request = BosClient::Request.new @bucket_host, method: :head response = request.run response[:result] end |
#destory ⇒ Object
25 26 27 28 29 |
# File 'lib/bos_client/bucket.rb', line 25 def destory request = BosClient::Request.new @bucket_host, method: :delete response = request.run response[:result] end |
#dir_objects(prefix, options = {}) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/bos_client/bucket.rb', line 45 def dir_objects(prefix, = {}) response = list_objects .merge(delimiter: '/', prefix: prefix) data = response[:data][:contents] objs = data.find_all { |e| !is_dir?(e[:key]) } objs.map { |obj| BosClient::Object.new ({bucket: self}.merge(obj)) } end |
#dirs(options = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/bos_client/bucket.rb', line 38 def dirs( = {}) response = list_objects data = response[:data][:contents] data = data.find_all { |e| is_dir?(e[:key]) } data.map { |e| e[:key] } end |
#objects(options = {}) ⇒ Object
objects
32 33 34 35 36 |
# File 'lib/bos_client/bucket.rb', line 32 def objects( = {}) response = list_objects .merge(delimiter: '/') objs = response[:data][:contents] objs.map { |obj| BosClient::Object.new ({bucket: self}.merge(obj)) } end |
#save ⇒ Object
19 20 21 22 23 |
# File 'lib/bos_client/bucket.rb', line 19 def save request = BosClient::Request.new @bucket_host, method: :put response = request.run response[:result] end |