Class: SweetyBacky::S3
- Inherits:
-
Object
- Object
- SweetyBacky::S3
- Defined in:
- lib/sweety_backy/s3.rb
Class Method Summary collapse
- .delete(path, opts) ⇒ Object
- .exists?(path, opts) ⇒ Boolean
- .object(path, opts) ⇒ Object
- .paths_in(path, opts) ⇒ Object
- .read_s3_password(path) ⇒ Object
- .upload(path, s3_path, opts) ⇒ Object
Class Method Details
.delete(path, opts) ⇒ Object
53 54 55 |
# File 'lib/sweety_backy/s3.rb', line 53 def self.delete( path, opts ) SweetyBacky::S3.object( path, opts ).delete end |
.exists?(path, opts) ⇒ Boolean
25 26 27 |
# File 'lib/sweety_backy/s3.rb', line 25 def self.exists?( path, opts ) return object( path, opts ).exists? end |
.object(path, opts) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/sweety_backy/s3.rb', line 17 def self.object( path, opts ) s3 = AWS::S3.new( read_s3_password( opts[:passwd_file] ) ) bucket = s3.buckets[ opts[:bucket] ] object = bucket.objects[ path ] object end |
.paths_in(path, opts) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sweety_backy/s3.rb', line 29 def self.paths_in( path, opts ) s3 = AWS::S3.new( read_s3_password( opts[:passwd_file] ) ) bucket = s3.buckets[ opts[:bucket] ] regex = Regexp.escape( path ).gsub('\*', '.*').gsub('\?', '.') objects = bucket.objects.select { |e| e.key =~ /^#{regex}$/ } paths = objects.map(&:key) return paths end |
.read_s3_password(path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sweety_backy/s3.rb', line 41 def self.read_s3_password( path ) opts = YAML.load( File.read( File. path ) ) new_opts = {} # symbolize keys opts.keys.each do |key| new_opts[key.to_sym] = opts[key] end return new_opts end |
.upload(path, s3_path, opts) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/sweety_backy/s3.rb', line 3 def self.upload( path, s3_path, opts ) SweetyBacky::Utils.log( "S3 uploading: #{path} to #{opts[:bucket]}/#{s3_path}" ) s3 = AWS::S3.new( read_s3_password( opts[:passwd_file] ) ) bucket = s3.buckets[ opts[:bucket] ] if !bucket.exists? bucket = s3.buckets.create( opts[:bucket] ) end object = bucket.objects[ s3_path ] object.write( :file => path ) end |