Class: S3SizeCalc::Calculator
- Inherits:
-
Object
- Object
- S3SizeCalc::Calculator
- Defined in:
- lib/s3sizecalc/calculator.rb
Instance Method Summary collapse
- #account_total ⇒ Object
- #bucket_total(bucket_name) ⇒ Object
- #current_region ⇒ Object
-
#initialize(options = {}) ⇒ Calculator
constructor
A new instance of Calculator.
- #region_total(region = current_region) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Calculator
Returns a new instance of Calculator.
8 9 10 |
# File 'lib/s3sizecalc/calculator.rb', line 8 def initialize( = {}) = end |
Instance Method Details
#account_total ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/s3sizecalc/calculator.rb', line 34 def account_total regions = ec2.client.describe_regions[:regions].map {|region| region[:region_name]} regions.inject 0 do |total, region| total += region_total(region) end end |
#bucket_total(bucket_name) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/s3sizecalc/calculator.rb', line 12 def bucket_total(bucket_name) puts "Calculating size of bucket `#{bucket_name}`." if .verbose s3.bucket(bucket_name).objects.inject 0 do |total, object| size = object.size puts "Size of object `#{object.key}` => #{size} bytes." if .very_verbose total += size end end |
#current_region ⇒ Object
42 43 44 |
# File 'lib/s3sizecalc/calculator.rb', line 42 def current_region @current_region || .region || own_region end |
#region_total(region = current_region) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/s3sizecalc/calculator.rb', line 22 def region_total(region = current_region) @current_region = region s3(region).buckets.inject 0 do |total, bucket| if s3.client.get_bucket_location(bucket: bucket.name).location_constraint == region total += bucket_total(bucket.name) else total end end end |