Class: Ralf::Bucket
- Inherits:
-
Object
- Object
- Ralf::Bucket
- Defined in:
- lib/ralf/bucket.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each_log(date) ⇒ Object
-
#initialize(bucket) ⇒ Bucket
constructor
A new instance of Bucket.
- #logging_enabled? ⇒ Boolean
- #name ⇒ Object
- #targetbucket ⇒ Object
- #targetprefix ⇒ Object
Constructor Details
#initialize(bucket) ⇒ Bucket
Returns a new instance of Bucket.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ralf/bucket.rb', line 7 def initialize(bucket) raise ArgumentError.new("Bucket.s3 not assigned yet") if @@s3.nil? @bucket = bucket @logging_info = @bucket.logging_info if @logging_info[:enabled] and @bucket.name != @logging_info[:targetbucket] @targetbucket = @@s3.bucket(@logging_info[:targetbucket]) else @targetbucket = @bucket end end |
Class Method Details
.each(names = nil, with_logging = true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ralf/bucket.rb', line 23 def self.each(names = nil, with_logging = true) # find specified buckets if names names.map do |name| if s3_bucket = @@s3.bucket(name) bucket = Bucket.new(s3_bucket) yield bucket if !with_logging or bucket.logging_enabled? else puts("Warning: bucket '#{name}' not found.") if bucket.nil? end end else @@s3.buckets.each do |s3_bucket| bucket = Bucket.new(s3_bucket) yield bucket if !with_logging or bucket.logging_enabled? end end end |
.s3=(s3) ⇒ Object
19 20 21 |
# File 'lib/ralf/bucket.rb', line 19 def self.s3=(s3) @@s3 = s3 end |
Instance Method Details
#each_log(date) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/ralf/bucket.rb', line 58 def each_log(date) search_string = "%s%s" % [@logging_info[:targetprefix], date] @targetbucket.keys(:prefix => search_string).each do |key| yield Log.new(key, @logging_info[:targetprefix]) end end |
#logging_enabled? ⇒ Boolean
46 47 48 |
# File 'lib/ralf/bucket.rb', line 46 def logging_enabled? !!@logging_info[:enabled] end |
#name ⇒ Object
42 43 44 |
# File 'lib/ralf/bucket.rb', line 42 def name @bucket.name end |
#targetbucket ⇒ Object
50 51 52 |
# File 'lib/ralf/bucket.rb', line 50 def targetbucket @logging_info[:targetbucket] end |
#targetprefix ⇒ Object
54 55 56 |
# File 'lib/ralf/bucket.rb', line 54 def targetprefix @logging_info[:targetprefix] end |