file-manager 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8eaf7733152d271b5aae936b8031ae7288363f9
4
+ data.tar.gz: f7a939e41d12b74c8aeef783067b404d2d0689ce
5
+ SHA512:
6
+ metadata.gz: 4ff119bebfb68dc776aad8f5878f189c1851e2c724147083f05406ad45e8f6a46d018fc7cbe70302e50a78334f26c0d2a059d87802a8ab1634ac8b3a3f7edff5
7
+ data.tar.gz: 94421f9cdc6f9a05f192be6539898b35c6e135ef68b8535ce77ae8574d37cbcb8b94eb800ca410868cad19c6d3b671257cbfa53f3d4a5f5e47bd774021b32ef1
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in file-manager.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Francisco Barroso
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # File::Manager
2
+
3
+ File manager local or S3
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'file-manager'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install file-manager
18
+
19
+ ## Usage
20
+
21
+ require 'file_manager_factory'
22
+
23
+ file_managers = {
24
+ xml_data: {
25
+ type: 'local',
26
+ root_path:'/Users/franciscobarroso/reports/'
27
+ },
28
+ txt: {
29
+ type: 'local',
30
+ root_path:'/Users/franciscobarroso/reports/'
31
+ }
32
+ }
33
+
34
+ factory = FileManagerFactory.new(file_managers)
35
+
36
+ file_manager_txt = factory.create(:txt)
37
+
38
+ file_manager_txt.save_file('babau.txt', 'buuuu')
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/config.rb ADDED
@@ -0,0 +1,14 @@
1
+ file_managers = {
2
+ xml_data: {
3
+ type: 'local',
4
+ root_path:'reports/'
5
+ },
6
+ jasper: {
7
+ type: 'local',
8
+ root_path:'reports/'
9
+ },
10
+ pdf: {
11
+ type: 'local',
12
+ root_path:'reports/'
13
+ }
14
+ }
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "file-manager"
6
+ spec.version = '0.0.3'
7
+ spec.authors = ["Francisco Barroso / Marlus Saraiva"]
8
+ spec.email = ["franciscobarroso@grupofortes.com.br"]
9
+ spec.description = 'File manager, access S3 or local'
10
+ spec.summary = 'File manager, access S3 or local'
11
+ spec.homepage = ''
12
+
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+ spec.homepage = 'https://github.com/fortesinformatica/file-manager'
18
+
19
+ spec.add_dependency 'aws-sdk', '~>1.52.0'
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,18 @@
1
+ require 's3_file_manager'
2
+ require 'local_file_manager'
3
+
4
+ class FileManagerFactory
5
+ FILE_MANAGERS = {
6
+ 'S3' => ::S3FileManager,
7
+ 'local' => ::LocalFileManager,
8
+ }
9
+
10
+ def initialize(file_managers_config)
11
+ @file_managers_config = file_managers_config
12
+ end
13
+
14
+ def create(name)
15
+ config = @file_managers_config[name]
16
+ FILE_MANAGERS[config[:type]].new config
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ class LocalFileManager
2
+
3
+ attr_accessor :options
4
+
5
+ def initialize options
6
+ @options = options
7
+ end
8
+
9
+ def read_file file_name
10
+ root_path = options[:root_path]
11
+ print "Reading file \"#{file_name}\" from local folder \"#{root_path}\"..."
12
+ contents = File.open("#{root_path}/#{file_name}", 'rb') { |f| f.read }
13
+ puts 'done.'
14
+
15
+ contents
16
+ end
17
+
18
+ def save_file file_name, file_contents
19
+ root_path = options[:root_path]
20
+ print "Saving file \"#{file_name}\" to local folder \"#{root_path}\"..."
21
+ File.open("#{root_path}/#{file_name}", 'wb') { |f| f.write(file_contents) }
22
+ puts 'done.'
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ require 'aws-sdk'
2
+
3
+ class S3FileManager
4
+ attr_accessor :options
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def read_file file_name
11
+ s3_service = connect_s3_service
12
+ bucket = s3_service.buckets[options[:bucket]]
13
+
14
+ print "Reading file \"#{file_name}\" from bucket \"#{:bucket}\"..."
15
+ contents = bucket.objects[file_name].read
16
+ puts 'done.'
17
+
18
+ contents
19
+ end
20
+
21
+ def save_file file_name, file_contents
22
+ print "Saving file \"#{file_name}\" to bucket \"#{:bucket}\"..."
23
+ s3_service = connect_s3_service
24
+ bucket = s3_service.buckets[options[:bucket]]
25
+
26
+ bucket.objects["#{file_name}"].write(file_contents.to_s)
27
+ puts 'done.'
28
+ end
29
+
30
+ private
31
+
32
+ def connect_s3_service
33
+ print "Accessing S3 service..."
34
+
35
+ AWS.config(
36
+ :access_key_id => options[:access_key_id],
37
+ :secret_access_key => options[:secret_access_key]
38
+ )
39
+
40
+ service = AWS::S3.new
41
+ puts 'done.'
42
+ service
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file-manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Francisco Barroso / Marlus Saraiva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.52.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.52.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: File manager, access S3 or local
56
+ email:
57
+ - franciscobarroso@grupofortes.com.br
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - config.rb
68
+ - file-manager.gemspec
69
+ - lib/file_manager_factory.rb
70
+ - lib/local_file_manager.rb
71
+ - lib/s3_file_manager.rb
72
+ homepage: https://github.com/fortesinformatica/file-manager
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.7
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: File manager, access S3 or local
95
+ test_files: []