Class: S3Cleaner::Clean

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_cleaner/clean.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Clean

Returns a new instance of Clean.



5
6
7
8
9
10
# File 'lib/s3_cleaner/clean.rb', line 5

def initialize(args)
  @bucket_name = args.fetch(:bucket_name)
  @prefix = args.fetch(:prefix)
  @num_releases = args.fetch(:num_releases)
  @aws_config = args.fetch(:aws_config)
end

Instance Attribute Details

#aws_configObject (readonly)

Returns the value of attribute aws_config.



3
4
5
# File 'lib/s3_cleaner/clean.rb', line 3

def aws_config
  @aws_config
end

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



3
4
5
# File 'lib/s3_cleaner/clean.rb', line 3

def bucket_name
  @bucket_name
end

#num_releasesObject (readonly)

Returns the value of attribute num_releases.



3
4
5
# File 'lib/s3_cleaner/clean.rb', line 3

def num_releases
  @num_releases
end

#prefixObject (readonly)

Returns the value of attribute prefix.



3
4
5
# File 'lib/s3_cleaner/clean.rb', line 3

def prefix
  @prefix
end

Instance Method Details

#delete_old_releasesObject



12
13
14
15
16
17
# File 'lib/s3_cleaner/clean.rb', line 12

def delete_old_releases
  return if directories_to_delete.nil? || directories_to_delete.empty?
  directories_to_delete.each do |dir|
    bucket.objects.with_prefix(dir).delete_all
  end
end

#directories_to_deleteObject



19
20
21
# File 'lib/s3_cleaner/clean.rb', line 19

def directories_to_delete
  @directories_to_delete ||= directories[num_releases..-1]
end