filestorage 0.0.1 → 0.0.2

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: 92b1178b4b2b89d57f276b5217906e6a1c13a8b5
4
- data.tar.gz: 7164e1d5e1a16a61713911d2445d3fa7aa587c0f
3
+ metadata.gz: 7d3a09a44d0a6e015dac0c4dd96874752c8fd779
4
+ data.tar.gz: 2efd36ab2311060c54a7b26b498329252fb3b9ed
5
5
  SHA512:
6
- metadata.gz: fd41edcfd1eb08f76bd7633a621dd13921cc7a80a2196c345198ad45d4d70c610a0ec2d2dacb47539c769f687cf85a883303c227e7e472cd251866da26a19ce4
7
- data.tar.gz: d353abb08b3b1287332b0ea304d31b6d35a7879509eca91734175e55cd6d2b2d06d6c5c82a548c3903ec516d7fa26929a27b617166921b34fc2a1a0705aabcb2
6
+ metadata.gz: 05df021049c6e585177447924c3167b28882d68ea779a009e98069bac70dee0f4cc2924a850bf202b5b7c5e8833c56ad1154a5ab599954bf4e53f3536cf004d7
7
+ data.tar.gz: 465e41208e173177bdd3dc29ed7dfdf37d8751b6b091b473f9d7e4d88aae906e5e704c722201f174adc40ebc41c814dff2a38e67d1956acc800a7fad49f8af8a
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,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in filestorage.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in filestorage.gemspec
4
+ gemspec
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,29 +1,41 @@
1
- # Filestorage
2
-
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it ( https://github.com/[my-github-username]/filestorage/fork )
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 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::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
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,23 @@
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -13,6 +13,7 @@ module Filestorage
13
13
 
14
14
  def store(path, file)
15
15
  fullpath = @base_dir + path
16
+ raise AlreadyExist.new("Already exist #{path}") if File.exist?(fullpath)
16
17
  FileUtils.mkdir_p(fullpath.parent)
17
18
  if file.instance_of?(Pathname)
18
19
  FileUtils.cp(file, fullpath)
@@ -30,9 +31,22 @@ module Filestorage
30
31
 
31
32
  def get(path)
32
33
  fullpath = @base_dir + path
34
+ raise NotExist.new("Not exist #{path}") unless File.exist?(fullpath)
33
35
  File.open(fullpath, "rb")
34
36
  end
35
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
+
36
50
  end # of class LocalFilestorage
37
51
 
38
52
  end # of module LocalFilestorage
@@ -1,3 +1,3 @@
1
- module Filestorage
2
- VERSION = "0.0.1"
3
- end
1
+ module Filestorage
2
+ VERSION = "0.0.2"
3
+ end
data/lib/filestorage.rb CHANGED
@@ -1,5 +1,7 @@
1
- require "filestorage/version"
2
- require "filestorage/local_filestorage"
3
-
4
- module Filestorage
5
- end
1
+ require "filestorage/version"
2
+ require "filestorage/local_filestorage"
3
+
4
+ module Filestorage
5
+ class NotExist < StandardError; end
6
+ class AlreadyExist < StandardError; end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filestorage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-03 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler