filestorage 0.0.3 → 0.0.4

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: 127bdfaa77c8a4487a8d59390e2fefe8896cb929
4
- data.tar.gz: 2baf8f28f227a1534575d128f89fc72fbdfe8cfa
3
+ metadata.gz: 7d4be62c341664440c3ebf2c3631a98d3e51e224
4
+ data.tar.gz: d082f7e3f9aa8796482351d67290dca1b6a5cae4
5
5
  SHA512:
6
- metadata.gz: 6aed5c1d8f6ce34ae7effffa94cc810b46307119b196652be53d6f7f510372a07ff89e1a14ae7e909b15b7877730b596046c542f9dd938f753c201eea4e835e3
7
- data.tar.gz: 73573b098183f4a74f1fdf9dff3c18abe7e883d759d7d44e5e242e40279a7243afb9d4ae8f26d867f0b40b05c46e757cf5930b2e5d9450e9f88277e431517eed
6
+ metadata.gz: 34e14d0732bb95e542e028bf10cd42df03e47d0201a3691de8a0e9f9cbea6c87e1e6c9ab969bbc5c69c979e6d45732c8f0b0c2ef79839b95151ff0150208c126
7
+ data.tar.gz: ffd4af8072795436b539d288ec76c0765473e1c5598e5db2a5bc5d22a235d918aa7836c902699a54a2e1c253b027411bab03598d38a71f7a85634b605a8c398e
data/.gitignore CHANGED
@@ -1,22 +1,22 @@
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
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in filestorage.gemspec
4
- gemspec
5
-
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in filestorage.gemspec
4
+ gemspec
5
+
6
6
  gem 'aws-sdk'
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2014 takatoh
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.
1
+ Copyright (c) 2014 takatoh
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 CHANGED
@@ -1,41 +1,41 @@
1
- # Filestorage
2
-
3
- A simple file storage.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'filestorage'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install filestorage
18
-
19
- ## Usage
20
-
21
- Create a instance.
22
-
23
- require 'filestorage'
24
- storage = Filesotrage::LocalFilesotrage.new(base_dir)
25
-
26
- Store a file to path.
27
-
28
- storage.store("foo/bar/baz.txt", file)
29
-
30
- And get the file. `get' method returns instance of File class.
31
-
32
- file = storage.get("foo/bar/baz.txt")
33
- content = file.read
34
-
35
- ## Contributing
36
-
37
- 1. Fork it ( https://github.com/takatoh/filestorage/fork )
38
- 2. Create your feature branch (`git checkout -b my-new-feature`)
39
- 3. Commit your changes (`git commit -am 'Add some feature'`)
40
- 4. Push to the branch (`git push origin my-new-feature`)
41
- 5. Create a new Pull Request
1
+ # Filestorage
2
+
3
+ A simple file storage.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'filestorage'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install filestorage
18
+
19
+ ## Usage
20
+
21
+ Create a instance.
22
+
23
+ require 'filestorage'
24
+ storage = Filesotrage::Local.new(base_dir)
25
+
26
+ Store a file to path.
27
+
28
+ storage.store("foo/bar/baz.txt", file)
29
+
30
+ And get the file. `get' method returns instance of File class.
31
+
32
+ file = storage.get("foo/bar/baz.txt")
33
+ content = file.read
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/takatoh/filestorage/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require "bundler/gem_tasks"
2
+
data/filestorage.gemspec CHANGED
@@ -1,23 +1,24 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'filestorage/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "filestorage"
8
- spec.version = Filestorage::VERSION
9
- spec.authors = ["takatoh"]
10
- spec.email = ["takatoh.m@gmail.com"]
11
- spec.summary = %q{A simple file storeage.}
12
- spec.description = %q{}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
23
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'filestorage/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "filestorage"
8
+ spec.version = Filestorage::VERSION
9
+ spec.authors = ["takatoh"]
10
+ spec.email = ["takatoh.m@gmail.com"]
11
+ spec.summary = %q{A simple file storeage.}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "aws-sdk"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -1,50 +1,50 @@
1
- # encoding: utf-8
2
-
3
- require 'aws'
4
-
5
-
6
- module Filestorage
7
-
8
- class S3Filestorage
9
-
10
- def initialize(bucket, access_key_id, secret_access_key)
11
- @s3 = AWS::S3.new(:access_key_id => access_key_id,
12
- :secret_access_key => secret_access_key)
13
- @bucket = @s3.buckets[bucket]
14
- end
15
-
16
- def store(path, file)
17
- obj = @bucket.objects[path]
18
- raise AlreadyExist.new("Already exist #{path}") if obj.exists?
19
- content = if file.instance_of?(Pathname)
20
- File.open(file, "rb"){|f| f.read}
21
- elsif file.instance_of?(File)
22
- file.read
23
- else
24
- file
25
- end
26
- obj.write(content, :acl => :public_read)
27
- path
28
- end
29
-
30
- def get(path)
31
- obj = @bucket.objects[path]
32
- raise NotExist.new("Not exist #{path}") unless obj.exists?
33
- obj
34
- end
35
-
36
- def delete(path)
37
- obj = @bucket.objects[path]
38
- raise NotExist.new("Not exist #{path}") unless obj.exists?
39
- obj.delete
40
- path
41
- end
42
-
43
- def exist?(path)
44
- obj = @bucket.objects[path]
45
- obj.exists?
46
- end
47
-
48
- end # of class S3Filestorage
49
-
50
- end # of module Filestorag
1
+ # encoding: utf-8
2
+
3
+ require 'aws'
4
+
5
+
6
+ module Filestorage
7
+
8
+ class AmazonS3
9
+
10
+ def initialize(bucket, access_key_id, secret_access_key)
11
+ @s3 = AWS::S3.new(:access_key_id => access_key_id,
12
+ :secret_access_key => secret_access_key)
13
+ @bucket = @s3.buckets[bucket]
14
+ end
15
+
16
+ def store(path, file)
17
+ obj = @bucket.objects[path]
18
+ raise AlreadyExist.new("Already exist #{path}") if obj.exists?
19
+ content = if file.instance_of?(Pathname)
20
+ File.open(file, "rb"){|f| f.read}
21
+ elsif file.instance_of?(File)
22
+ file.read
23
+ else
24
+ file
25
+ end
26
+ obj.write(content, :acl => :public_read)
27
+ path
28
+ end
29
+
30
+ def get(path)
31
+ obj = @bucket.objects[path]
32
+ raise NotExist.new("Not exist #{path}") unless obj.exists?
33
+ obj
34
+ end
35
+
36
+ def delete(path)
37
+ obj = @bucket.objects[path]
38
+ raise NotExist.new("Not exist #{path}") unless obj.exists?
39
+ obj.delete
40
+ path
41
+ end
42
+
43
+ def exist?(path)
44
+ obj = @bucket.objects[path]
45
+ obj.exists?
46
+ end
47
+
48
+ end # of class AmazonS3
49
+
50
+ end # of module Filestorag
@@ -1,52 +1,52 @@
1
- # encoding: utf-8
2
-
3
- require 'pathname'
4
- require 'fileutils'
5
-
6
- module Filestorage
7
-
8
- class LocalFilestorage
9
-
10
- def initialize(base_dir)
11
- @base_dir = Pathname.new(base_dir)
12
- end
13
-
14
- def store(path, file)
15
- fullpath = @base_dir + path
16
- raise AlreadyExist.new("Already exist #{path}") if File.exist?(fullpath)
17
- FileUtils.mkdir_p(fullpath.parent)
18
- if file.instance_of?(Pathname)
19
- FileUtils.cp(file, fullpath)
20
- elsif file.instance_of?(File)
21
- File.open(fullpath, "wb") do |f|
22
- f.write(file.read)
23
- end
24
- else
25
- File.open(fullpath, "wb") do |f|
26
- f.write(file)
27
- end
28
- end
29
- path
30
- end
31
-
32
- def get(path)
33
- fullpath = @base_dir + path
34
- raise NotExist.new("Not exist #{path}") unless File.exist?(fullpath)
35
- File.open(fullpath, "rb")
36
- end
37
-
38
- def delete(path)
39
- fullpath = @base_dir + path
40
- raise NotExist.new("Not exist #{path}") unless File.exist?(fullpath)
41
- FileUtils.rm(fullpath)
42
- path
43
- end
44
-
45
- def exist?(path)
46
- fullpath = @base_dir + path
47
- File.exist?(fullpath)
48
- end
49
-
50
- end # of class LocalFilestorage
51
-
52
- end # of module LocalFilestorage
1
+ # encoding: utf-8
2
+
3
+ require 'pathname'
4
+ require 'fileutils'
5
+
6
+ module Filestorage
7
+
8
+ class Local
9
+
10
+ def initialize(base_dir)
11
+ @base_dir = Pathname.new(base_dir)
12
+ end
13
+
14
+ def store(path, file)
15
+ fullpath = @base_dir + path
16
+ raise AlreadyExist.new("Already exist #{path}") if File.exist?(fullpath)
17
+ FileUtils.mkdir_p(fullpath.parent)
18
+ if file.instance_of?(Pathname)
19
+ FileUtils.cp(file, fullpath)
20
+ elsif file.instance_of?(File)
21
+ File.open(fullpath, "wb") do |f|
22
+ f.write(file.read)
23
+ end
24
+ else
25
+ File.open(fullpath, "wb") do |f|
26
+ f.write(file)
27
+ end
28
+ end
29
+ path
30
+ end
31
+
32
+ def get(path)
33
+ fullpath = @base_dir + path
34
+ raise NotExist.new("Not exist #{path}") unless File.exist?(fullpath)
35
+ File.open(fullpath, "rb")
36
+ end
37
+
38
+ def delete(path)
39
+ fullpath = @base_dir + path
40
+ raise NotExist.new("Not exist #{path}") unless File.exist?(fullpath)
41
+ FileUtils.rm(fullpath)
42
+ path
43
+ end
44
+
45
+ def exist?(path)
46
+ fullpath = @base_dir + path
47
+ File.exist?(fullpath)
48
+ end
49
+
50
+ end # of class Local
51
+
52
+ end # of module LocalFilestorage
@@ -1,3 +1,3 @@
1
- module Filestorage
2
- VERSION = "0.0.3"
3
- end
1
+ module Filestorage
2
+ VERSION = "0.0.4"
3
+ end
data/lib/filestorage.rb CHANGED
@@ -1,8 +1,8 @@
1
- require "filestorage/version"
2
- require "filestorage/local_filestorage"
3
- require "filestorage/s3_filestorage"
4
-
5
- module Filestorage
6
- class NotExist < StandardError; end
7
- class AlreadyExist < StandardError; end
8
- end
1
+ require "filestorage/version"
2
+ require "filestorage/local"
3
+ require "filestorage/amazon_s3"
4
+
5
+ module Filestorage
6
+ class NotExist < StandardError; end
7
+ class AlreadyExist < StandardError; end
8
+ end
metadata CHANGED
@@ -1,41 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filestorage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - takatoh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-04 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ~>
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
33
  version: '1.6'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ~>
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.6'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - '>='
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - '>='
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  description: ''
@@ -45,15 +59,15 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
- - .gitignore
62
+ - ".gitignore"
49
63
  - Gemfile
50
64
  - LICENSE.txt
51
65
  - README.md
52
66
  - Rakefile
53
67
  - filestorage.gemspec
54
68
  - lib/filestorage.rb
55
- - lib/filestorage/local_filestorage.rb
56
- - lib/filestorage/s3_filestorage.rb
69
+ - lib/filestorage/amazon_s3.rb
70
+ - lib/filestorage/local.rb
57
71
  - lib/filestorage/version.rb
58
72
  homepage: ''
59
73
  licenses:
@@ -65,17 +79,17 @@ require_paths:
65
79
  - lib
66
80
  required_ruby_version: !ruby/object:Gem::Requirement
67
81
  requirements:
68
- - - '>='
82
+ - - ">="
69
83
  - !ruby/object:Gem::Version
70
84
  version: '0'
71
85
  required_rubygems_version: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - '>='
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  requirements: []
77
91
  rubyforge_project:
78
- rubygems_version: 2.0.14
92
+ rubygems_version: 2.3.0
79
93
  signing_key:
80
94
  specification_version: 4
81
95
  summary: A simple file storeage.