file-manager 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/file-manager.gemspec +1 -1
- data/lib/file_manager.rb +41 -0
- data/lib/local_file_manager.rb +15 -15
- data/lib/memory_file_manager.rb +4 -3
- data/lib/s3_file_manager.rb +2 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95ef9d7130de0b05eb927258edf09389d1257a32
|
4
|
+
data.tar.gz: d6dd7a714b5c9b3e242bedfa6024c9ef540e4eab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a4ac89e1388c6e404a1072a383c65d634136da3a3c6086369442813f2c803c1549eb04b86cb56570353b06be0fc96e2f539ff5fa936e2c6276b13de324d1d2
|
7
|
+
data.tar.gz: d8664e7cef40fe4d85749f390b3c00f52f645b044beab69d8dd5fd699a21b07b8ff966c0eb112ff8c6e2229b88a2678734bdb732019f1e364badef0053d96162
|
data/.gitignore
CHANGED
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.
|
6
|
+
spec.version = '0.0.10'
|
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'
|
data/lib/file_manager.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class FileManager
|
2
|
+
|
3
|
+
attr_accessor :options
|
4
|
+
|
5
|
+
def initialize options
|
6
|
+
@options = options
|
7
|
+
@logger = FileManager::Logger.new options
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_file file_name
|
11
|
+
raise 'Not implemented!'
|
12
|
+
end
|
13
|
+
|
14
|
+
def save_file(file_name, file_contents, write_options = {})
|
15
|
+
raise 'Not implemented!'
|
16
|
+
end
|
17
|
+
|
18
|
+
def list_files(prefix = '', file_extension = '*')
|
19
|
+
raise 'Not implemented!'
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_file file_name
|
23
|
+
raise 'Not implemented!'
|
24
|
+
end
|
25
|
+
|
26
|
+
class Logger
|
27
|
+
|
28
|
+
def initialize options
|
29
|
+
@options = options
|
30
|
+
end
|
31
|
+
|
32
|
+
def print(text)
|
33
|
+
super text unless @options[:silent]
|
34
|
+
end
|
35
|
+
|
36
|
+
def puts(text)
|
37
|
+
super text unless @options[:silent]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/local_file_manager.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
|
1
|
+
require 'fileutils'
|
2
|
+
require 'file_manager'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
def initialize options
|
6
|
-
@options = options
|
7
|
-
end
|
4
|
+
class LocalFileManager < FileManager
|
8
5
|
|
9
6
|
def read_file file_name
|
10
7
|
root_path = options[:root_path]
|
11
|
-
print "Reading file \"#{file_name}\" from local folder \"#{root_path}\"..."
|
8
|
+
@logger.print "Reading file \"#{file_name}\" from local folder \"#{root_path}\"..."
|
12
9
|
contents = File.open("#{root_path}/#{file_name}", 'r:UTF-8') { |f| f.read }
|
13
|
-
puts 'done.'
|
10
|
+
@logger.puts 'done.'
|
14
11
|
|
15
12
|
contents
|
16
13
|
end
|
17
14
|
|
18
15
|
def save_file(file_name, file_contents, write_options = {})
|
19
16
|
root_path = options[:root_path]
|
20
|
-
|
17
|
+
FileUtils.mkdir_p(root_path)
|
18
|
+
@logger.print "Saving file \"#{file_name}\" to local folder \"#{root_path}\"..."
|
21
19
|
File.open("#{root_path}/#{file_name}", 'wb') { |f| f.write(file_contents) }
|
22
|
-
puts 'done.'
|
20
|
+
@logger.puts 'done.'
|
23
21
|
end
|
24
22
|
|
25
23
|
def list_files(prefix = '', file_extension = '*')
|
26
24
|
root_path = options[:root_path]
|
27
|
-
|
25
|
+
FileUtils.mkdir_p(root_path)
|
26
|
+
@logger.print "Listing \"#{prefix}*.#{file_extension}\" from local folder \"#{root_path}\"..."
|
28
27
|
files = Dir["#{root_path}/#{prefix}*.#{file_extension}"].map{|f| File.basename(f)}
|
29
|
-
puts 'done.'
|
28
|
+
@logger.puts 'done.'
|
30
29
|
files
|
31
30
|
end
|
32
31
|
|
33
32
|
def delete_file file_name
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
root_path = options[:root_path]
|
34
|
+
@logger.print "Deleting file \"#{file_name}\" from local folder \"#{root_path}\"..."
|
35
|
+
File.delete("#{root_path}/#{file_name}")
|
36
|
+
@logger.puts 'done.'
|
37
37
|
end
|
38
38
|
end
|
data/lib/memory_file_manager.rb
CHANGED
data/lib/s3_file_manager.rb
CHANGED
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.
|
4
|
+
version: 0.0.10
|
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: 2015-04-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- config.rb
|
68
68
|
- file-manager.gemspec
|
69
|
+
- lib/file_manager.rb
|
69
70
|
- lib/file_manager_factory.rb
|
70
71
|
- lib/local_file_manager.rb
|
71
72
|
- lib/memory_file_manager.rb
|