file-manager 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d897a0755f65ea57fef0f1312de6611944210ca4
4
- data.tar.gz: 99d9c13372811865c9a35f2a84172bfc3e1213a4
3
+ metadata.gz: 29c2d638972395f5c59c9e55f89ac8bac0d96813
4
+ data.tar.gz: 1fe20f17e246ee8e273a8f6dcd9675fd21da83d0
5
5
  SHA512:
6
- metadata.gz: db417873de14c8c194eaafd02a733505c2b9d145874be4c46bd3c65fc596eafc7b4472ba653fb9dd7fbf3aab53161a33508b98750f08284424819d920d0eb0c5
7
- data.tar.gz: 4378b9431785d4913820cfa629ee590dcaf64e55578a4e0d89e4b9ba418e1dd2e587d15bfb4bb754ad0fae9e5a6bb88009099c62b1e260d2db1f7800a705eed1
6
+ metadata.gz: 04ec7d1e4496580662051a5ac2a0755c05146ae3449645a5d467ddf4800f636b3998ecb36ea151b830ef8658f7b673babbb5487973231a9c10f09cbfa5b3e793
7
+ data.tar.gz: 15fb48e91ea9fbfea45f258c3112d9cb0bab936deb6b7a95c21bba8a5c3f7cb552e57f500d8d0bb4dd3c646bb5cdfa11ec9ba00b0409b4bfcf24794fbaaaef89
data/file-manager.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "file-manager"
6
- spec.version = '0.0.8'
6
+ spec.version = '0.0.9'
7
7
  spec.authors = ["Francisco Barroso / Marlus Saraiva"]
8
8
  spec.email = ["franciscobarroso@grupofortes.com.br"]
9
9
  spec.description = 'File manager, access S3 or local'
@@ -21,4 +21,18 @@ class LocalFileManager
21
21
  File.open("#{root_path}/#{file_name}", 'wb') { |f| f.write(file_contents) }
22
22
  puts 'done.'
23
23
  end
24
+
25
+ def list_files(prefix = '', file_extension = '*')
26
+ root_path = options[:root_path]
27
+ print "Listing \"#{prefix}*.#{file_extension}\" from local folder \"#{root_path}\"..."
28
+ files = Dir["#{root_path}/#{prefix}*.#{file_extension}"].map{|f| File.basename(f)}
29
+ puts 'done.'
30
+ files
31
+ end
32
+
33
+ def delete_file file_name
34
+ print "Deleting file \"#{file_name}\" from local folder \"#{root_path}\"..."
35
+ File.delete(file_name)
36
+ puts 'done.'
37
+ end
24
38
  end
@@ -14,4 +14,12 @@ class MemoryFileManager
14
14
  @data["#{file_name}"] = file_contents.to_s
15
15
  end
16
16
 
17
+ def list_files(prefix = '', file_extension = '*')
18
+ @data.keys.select{|key| key.start_with?(prefix) && key.end_with?(".#{file_extension}")}
19
+ end
20
+
21
+ def delete_file file_name
22
+ @data.delete "#{file_name}"
23
+ end
24
+
17
25
  end
@@ -27,6 +27,42 @@ class S3FileManager
27
27
  puts 'done.'
28
28
  end
29
29
 
30
+ def list_files(prefix = '', file_extension = '*')
31
+ # objects = []
32
+ # last_key = nil
33
+ # begin
34
+ # new_objects = AWS::S3::Bucket.objects(bucket_name, :marker => last_key)
35
+ # objects += new_objects
36
+ # last_key = objects.last.key
37
+ # end while new_objects.size > 0
38
+ #
39
+ # bucket = s3_service.buckets[options[:bucket]]
40
+ # bucket.each do |object|
41
+ # puts "#{object.key}\t#{object.about['content-length']}\t#{object.about['last-modified']}"
42
+ # end
43
+
44
+ s3_service = connect_s3_service
45
+ bucket = s3_service.buckets[options[:bucket]]
46
+
47
+ print "Listing \"#{prefix}*.#{file_extension}\" from bucket \"#{options[:bucket]}\"..."
48
+
49
+ files = []
50
+ bucket.objects.with_prefix(prefix).each(:limit => 1000) do |obj|
51
+ if file_extension == '*' || obj.key.end_with?(".#{file_extension}")
52
+ files << obj.key
53
+ end
54
+ end
55
+ puts 'done.'
56
+ files
57
+ end
58
+
59
+ def delete_file file_name
60
+ bucket = s3_service.buckets[options[:bucket]]
61
+ print "Deleting file \"#{file_name}\" from bucket \"#{options[:bucket]}\"..."
62
+ bucket.objects[file_name].delete
63
+ puts 'done.'
64
+ end
65
+
30
66
  private
31
67
 
32
68
  def connect_s3_service
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Barroso / Marlus Saraiva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk