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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29c2d638972395f5c59c9e55f89ac8bac0d96813
4
- data.tar.gz: 1fe20f17e246ee8e273a8f6dcd9675fd21da83d0
3
+ metadata.gz: 95ef9d7130de0b05eb927258edf09389d1257a32
4
+ data.tar.gz: d6dd7a714b5c9b3e242bedfa6024c9ef540e4eab
5
5
  SHA512:
6
- metadata.gz: 04ec7d1e4496580662051a5ac2a0755c05146ae3449645a5d467ddf4800f636b3998ecb36ea151b830ef8658f7b673babbb5487973231a9c10f09cbfa5b3e793
7
- data.tar.gz: 15fb48e91ea9fbfea45f258c3112d9cb0bab936deb6b7a95c21bba8a5c3f7cb552e57f500d8d0bb4dd3c646bb5cdfa11ec9ba00b0409b4bfcf24794fbaaaef89
6
+ metadata.gz: e7a4ac89e1388c6e404a1072a383c65d634136da3a3c6086369442813f2c803c1549eb04b86cb56570353b06be0fc96e2f539ff5fa936e2c6276b13de324d1d2
7
+ data.tar.gz: d8664e7cef40fe4d85749f390b3c00f52f645b044beab69d8dd5fd699a21b07b8ff966c0eb112ff8c6e2229b88a2678734bdb732019f1e364badef0053d96162
data/.gitignore CHANGED
@@ -16,4 +16,5 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
 
19
- .idea/
19
+ .idea/
20
+ *.iml
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.9'
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'
@@ -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
@@ -1,38 +1,38 @@
1
- class LocalFileManager
1
+ require 'fileutils'
2
+ require 'file_manager'
2
3
 
3
- attr_accessor :options
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
- print "Saving file \"#{file_name}\" to local folder \"#{root_path}\"..."
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
- print "Listing \"#{prefix}*.#{file_extension}\" from local folder \"#{root_path}\"..."
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
- print "Deleting file \"#{file_name}\" from local folder \"#{root_path}\"..."
35
- File.delete(file_name)
36
- puts 'done.'
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
@@ -1,8 +1,9 @@
1
- class MemoryFileManager
2
- attr_accessor :options
1
+ require 'file_manager'
2
+
3
+ class MemoryFileManager < FileManager
3
4
 
4
5
  def initialize(options)
5
- @options = options
6
+ super
6
7
  @data = {}
7
8
  end
8
9
 
@@ -1,11 +1,7 @@
1
+ require 'file_manager'
1
2
  require 'aws-sdk'
2
3
 
3
- class S3FileManager
4
- attr_accessor :options
5
-
6
- def initialize(options)
7
- @options = options
8
- end
4
+ class S3FileManager < FileManager
9
5
 
10
6
  def read_file file_name
11
7
  s3_service = 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.9
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-06 00:00:00.000000000 Z
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