temppath 0.1.0

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.
@@ -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
+ html
19
+ gems
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in temppath.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Keita Yamaguchi
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.
@@ -0,0 +1,30 @@
1
+ # Temppath
2
+
3
+ Temppath is a Ruby library for generating temporary file path. The differences
4
+ from standard tempfile.rb are that this library generates Pathname objects with
5
+ no files and filenames are based on UUID. Files in paths generated by this are
6
+ deleted when Ruby exits.
7
+
8
+ ## Installation
9
+
10
+ $ gem install temppath
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+ path = Temppath.create
16
+ #=> #<Pathname:/tmp/ruby-temppath-20130407-5775-w5k77l/f41bd6c5-fc99-4b7a-8f68-95b7ae4a6b22>
17
+ path.exist? #=> false
18
+ ```
19
+
20
+ ## Licence
21
+
22
+ Temppath is free software distributed under MIT licence.
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'Test specs'
4
+ task 'test' do
5
+ sh "bundle exec bacon -a"
6
+ end
7
+
8
+ desc 'Generate API document'
9
+ task 'html' do
10
+ sh "bundle exec yard doc -o html --hide-void-return --no-api"
11
+ end
12
+
13
+ desc 'Show undocumented function list'
14
+ task 'html:undoc' do
15
+ sh "bundle exec yard stats --list-undoc --no-api --compact"
16
+ end
@@ -0,0 +1,58 @@
1
+ require 'temppath/version'
2
+ require 'uuidtools'
3
+ require 'pathname'
4
+ require 'tmpdir'
5
+ require 'fileutils'
6
+
7
+ # Temppath creates temporary path. The differences from standard tempfile.rb are
8
+ # that this library generates Pathname objects with no files and filenames are
9
+ # based on UUID. Files in paths generated by this are deleted when Ruby exits.
10
+ #
11
+ # @example
12
+ # path = Temppath.create
13
+ # #=> #<Pathname:/tmp/ruby-temppath-20130407-5775-w5k77l/f41bd6c5-fc99-4b7a-8f68-95b7ae4a6b22>
14
+ # path.exist? #=> false
15
+ module Temppath
16
+ @dir = Pathname.new(Dir.mktmpdir("ruby-temppath-"))
17
+ @unlink = true
18
+
19
+ class << self
20
+ # @return [Pathname]
21
+ # defalut temporary directory for paths created by Temppath
22
+ attr_reader :dir
23
+
24
+ # @return [Boolean]
25
+ # true if unlink mode is enabled
26
+ attr_accessor :unlink
27
+
28
+ # Create a temporary path. This method creates no files.
29
+ #
30
+ # @param basename [String]
31
+ # prefix of filename
32
+ # @param tmpdir [Pathname]
33
+ # pathname of temporary directory
34
+ def create(basename="", tmpdir=dir)
35
+ path = Pathname.new(tmpdir) + (basename.to_s + generate_uuid)
36
+ if tmpdir != dir
37
+ Kernel.at_exit {FileUtils.remove_entry_secure(path) rescue Errno::ENOENT}
38
+ end
39
+ return path
40
+ end
41
+
42
+ # Generate random UUID for filename of temporary path.
43
+ #
44
+ # @return [String]
45
+ # UUID string
46
+ def generate_uuid
47
+ UUIDTools::UUID.random_create.to_s
48
+ end
49
+ private :generate_uuid
50
+ end
51
+ end
52
+
53
+ # Remove Temppath's temporary directory.
54
+ Kernel.at_exit do
55
+ if Temppath.unlink
56
+ FileUtils.remove_entry_secure(Temppath.dir) rescue Errno::ENOENT
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ module Temppath
2
+ # version of temppath gem
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+ # -*- encoding: utf-8 -*-
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'temppath/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "temppath"
9
+ gem.version = Temppath::VERSION
10
+ gem.authors = ["Keita Yamaguchi"]
11
+ gem.email = ["keita.yamaguchi@gmail.com"]
12
+ gem.description = "temppath provides the method to create temporary path"
13
+ gem.summary = "temppath provides the method to create temporary path"
14
+ gem.homepage = "https://github.com/keita/temppath"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency "uuidtools", "~> 2.1.3"
22
+ gem.add_development_dependency "bacon", "~> 1.2.0"
23
+ gem.add_development_dependency "yard"
24
+ gem.add_development_dependency "redcarpet"
25
+ gem.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,31 @@
1
+ require 'temppath'
2
+
3
+ describe 'Temppath' do
4
+ it 'should get temporary path' do
5
+ Temppath.create.should.kind_of Pathname
6
+ Temppath.create.should != Temppath.create
7
+ end
8
+
9
+ it 'should get temporary path with basename' do
10
+ Temppath.create("A_").basename.to_s[0,2].should == "A_"
11
+ end
12
+
13
+ it 'should get temporary path with tmpdir' do
14
+ dir = Dir.tmpdir
15
+ Temppath.create(nil, dir).dirname.should == Pathname.new(dir)
16
+ end
17
+
18
+ it 'should be in the temporary directory' do
19
+ Temppath.create.dirname.should == Temppath.dir
20
+ end
21
+
22
+ it 'should get unlink mode' do
23
+ Temppath.unlink.should == true
24
+ end
25
+
26
+ it 'should set unlink mode' do
27
+ Temppath.unlink = false
28
+ Temppath.unlink.should == false
29
+ Temppath.unlink = true
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: temppath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Keita Yamaguchi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: uuidtools
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: bacon
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: redcarpet
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: temppath provides the method to create temporary path
95
+ email:
96
+ - keita.yamaguchi@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - lib/temppath.rb
107
+ - lib/temppath/version.rb
108
+ - temppath.gemspec
109
+ - test/spec_temppath.rb
110
+ homepage: https://github.com/keita/temppath
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: 3842158434666347241
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ segments:
132
+ - 0
133
+ hash: 3842158434666347241
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.24
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: temppath provides the method to create temporary path
140
+ test_files:
141
+ - test/spec_temppath.rb
142
+ has_rdoc: