open-temporary 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +43 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +19 -0
- data/README.rdoc +19 -0
- data/Rakefile +85 -0
- data/VERSION +1 -0
- data/ext/open_temporary/.gitignore +4 -0
- data/ext/open_temporary/extconf.rb +36 -0
- data/ext/open_temporary/open_temporary.c +86 -0
- data/lib/open-temporary.rb +74 -0
- data/open-temporary.gemspec +73 -0
- data/spec/open-temporary_spec.rb +62 -0
- data/spec/spec_helper.rb +44 -0
- metadata +178 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included
|
11
|
+
# in all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
source 'http://rubygems.org'
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem 'rake', '~> 0.9.0'
|
25
|
+
gem 'rspec', '~> 2.8.0'
|
26
|
+
gem 'yard', '~> 0.7'
|
27
|
+
gem 'rdoc', '~> 3.12'
|
28
|
+
gem 'bundler', '~> 1.2.0'
|
29
|
+
gem 'jeweler', '~> 1.8.4'
|
30
|
+
gem 'simplecov', '>= 0'
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Local Variables:
|
35
|
+
# mode: ruby
|
36
|
+
# coding: utf-8
|
37
|
+
# indent-tabs-mode: t
|
38
|
+
# tab-width: 3
|
39
|
+
# ruby-indent-level: 3
|
40
|
+
# fill-column: 79
|
41
|
+
# default-justification: full
|
42
|
+
# End:
|
43
|
+
# vi: ts=3 sw=3
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.5)
|
12
|
+
multi_json (1.3.6)
|
13
|
+
rake (0.9.2.2)
|
14
|
+
rdoc (3.12)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.8.0)
|
17
|
+
rspec-core (~> 2.8.0)
|
18
|
+
rspec-expectations (~> 2.8.0)
|
19
|
+
rspec-mocks (~> 2.8.0)
|
20
|
+
rspec-core (2.8.0)
|
21
|
+
rspec-expectations (2.8.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.8.0)
|
24
|
+
simplecov (0.6.4)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
simplecov-html (~> 0.5.3)
|
27
|
+
simplecov-html (0.5.3)
|
28
|
+
yard (0.8.2.1)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 1.2.0)
|
35
|
+
jeweler (~> 1.8.4)
|
36
|
+
rake (~> 0.9.0)
|
37
|
+
rdoc (~> 3.12)
|
38
|
+
rspec (~> 2.8.0)
|
39
|
+
simplecov
|
40
|
+
yard (~> 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included
|
11
|
+
in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= open-temporary
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to open-temporary
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Urabe, Shyouhei. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included
|
11
|
+
# in all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require 'bundler'
|
23
|
+
begin
|
24
|
+
Bundler.setup(:default, :development)
|
25
|
+
rescue Bundler::BundlerError => e
|
26
|
+
$stderr.puts e.message
|
27
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
28
|
+
exit e.status_code
|
29
|
+
end
|
30
|
+
require 'rake'
|
31
|
+
require 'rake/clean'
|
32
|
+
# use 'rake clean' and 'rake clobber' to
|
33
|
+
# easily delete generated files
|
34
|
+
CLEAN.include('ext/**/*{.o,.log,.so}')
|
35
|
+
CLOBBER.include('ext/**/Makefile')
|
36
|
+
|
37
|
+
soname = 'ext/open_temporary/open_temporary.so'
|
38
|
+
|
39
|
+
file soname => Dir.glob('ext/open_temporary/*.{rb,c}') do
|
40
|
+
Dir.chdir 'ext/open_temporary' do
|
41
|
+
ruby 'extconf.rb'
|
42
|
+
sh 'make'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
require 'rspec/core'
|
48
|
+
require 'rspec/core/rake_task'
|
49
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
50
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
51
|
+
end
|
52
|
+
task spec: soname
|
53
|
+
|
54
|
+
require 'yard'
|
55
|
+
YARD::Rake::YardocTask.new
|
56
|
+
|
57
|
+
require 'jeweler'
|
58
|
+
Jeweler::Tasks.new do |gem|
|
59
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
60
|
+
gem.name = "open-temporary"
|
61
|
+
gem.homepage = "http://github.com/shyouhei/open-temporary"
|
62
|
+
gem.license = "MIT"
|
63
|
+
gem.summary = "A variant of Tempfile that makes File instead"
|
64
|
+
gem.description = "A variation of tempfile standard lib, that actually creates a File instance."
|
65
|
+
gem.email = "shyouhei@ruby-lang.org"
|
66
|
+
gem.authors = ["Urabe, Shyouhei"]
|
67
|
+
# dependencies defined in Gemfile
|
68
|
+
end
|
69
|
+
Jeweler::RubygemsDotOrgTasks.new
|
70
|
+
rescue LoadError
|
71
|
+
# OK, they can be absent on non-development mode.
|
72
|
+
end
|
73
|
+
|
74
|
+
task default: soname
|
75
|
+
|
76
|
+
#
|
77
|
+
# Local Variables:
|
78
|
+
# mode: ruby
|
79
|
+
# coding: utf-8-unix
|
80
|
+
# indent-tabs-mode: t
|
81
|
+
# tab-width: 3
|
82
|
+
# ruby-indent-level: 3
|
83
|
+
# fill-column: 79
|
84
|
+
# default-justification: full
|
85
|
+
# End:
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included
|
11
|
+
# in all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require 'mkmf'
|
22
|
+
have_func("mkstemp", "stdlib.h") and
|
23
|
+
have_func("unlink", "unistd.h") and
|
24
|
+
have_func("fcntl", "fcntl.h") and
|
25
|
+
create_makefile 'open_temporary'
|
26
|
+
|
27
|
+
#
|
28
|
+
# Local Variables:
|
29
|
+
# mode: ruby
|
30
|
+
# coding: utf-8-unix
|
31
|
+
# indent-tabs-mode: t
|
32
|
+
# tab-width: 3
|
33
|
+
# ruby-indent-level: 3
|
34
|
+
# fill-column: 79
|
35
|
+
# default-justification: full
|
36
|
+
# End:
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/* Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included
|
11
|
+
* in all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include <ruby.h>
|
23
|
+
#include <stdlib.h>
|
24
|
+
#include <unistd.h>
|
25
|
+
#include <fcntl.h>
|
26
|
+
|
27
|
+
static VALUE tmpdir = Qundef;
|
28
|
+
static VALUE tmpsuf = Qundef;
|
29
|
+
|
30
|
+
static VALUE
|
31
|
+
open_temporary(int argc, VALUE* argv, VALUE klass)
|
32
|
+
{
|
33
|
+
char* str = NULL;
|
34
|
+
int fd = -1;
|
35
|
+
VALUE buf = Qundef;
|
36
|
+
VALUE dir = Qundef;
|
37
|
+
VALUE suf = Qundef;
|
38
|
+
int mod = -1;
|
39
|
+
|
40
|
+
rb_scan_args(argc, argv, "02", &dir, &suf);
|
41
|
+
|
42
|
+
if (dir == Qnil) dir = tmpdir;
|
43
|
+
if (suf == Qnil) suf = tmpsuf;
|
44
|
+
|
45
|
+
SafeStringValue(dir);
|
46
|
+
SafeStringValue(suf);
|
47
|
+
|
48
|
+
buf = rb_sprintf("%s/%sXXXXXX", StringValueCStr(dir), StringValueCStr(suf));
|
49
|
+
str = StringValueCStr(buf);
|
50
|
+
if ((fd = mkstemp(str)) == -1) {
|
51
|
+
rb_sys_fail("mkstemp(3)");
|
52
|
+
}
|
53
|
+
else if (unlink(str) == -1) {
|
54
|
+
/* unlink failed, no way to reclaim */
|
55
|
+
rb_sys_fail("unlink(2)");
|
56
|
+
}
|
57
|
+
else if ((mod = fcntl(fd, F_GETFL)) == -1) {
|
58
|
+
rb_sys_fail("fcntl(2)");
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
return rb_io_fdopen(fd, mod, str);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
extern void
|
66
|
+
Init_open_temporary(void)
|
67
|
+
{
|
68
|
+
rb_require("tmpdir");
|
69
|
+
tmpdir = rb_funcall(rb_cDir, rb_intern("tmpdir"), 0);
|
70
|
+
tmpsuf = rb_str_new_cstr("tmp");
|
71
|
+
rb_gc_register_mark_object(tmpdir);
|
72
|
+
rb_gc_register_mark_object(tmpsuf);
|
73
|
+
rb_define_singleton_method(rb_cFile, "open_temporary", open_temporary, -1);
|
74
|
+
}
|
75
|
+
|
76
|
+
/*
|
77
|
+
* Local Variables:
|
78
|
+
* mode: C
|
79
|
+
* c-file-style: "Stroustrup"
|
80
|
+
* coding: utf-8-unix
|
81
|
+
* indent-tabs-mode: nil
|
82
|
+
* tab-width: 8
|
83
|
+
* fill-column: 79
|
84
|
+
* default-justification: full
|
85
|
+
* End:
|
86
|
+
*/
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included
|
11
|
+
# in all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require 'open_temporary.so'
|
22
|
+
|
23
|
+
class File
|
24
|
+
@@open = self.method(:open)
|
25
|
+
|
26
|
+
# If non-zero numbers of args are passed, works as it ought.
|
27
|
+
# otherwise creates and opens a temporay file.
|
28
|
+
def self.open(*argv, &block)
|
29
|
+
if argv.size.nonzero?
|
30
|
+
@@open.call(*argv, &block)
|
31
|
+
elsif block_given?
|
32
|
+
begin
|
33
|
+
f = self.open_temporary
|
34
|
+
yield f
|
35
|
+
ensure
|
36
|
+
f.close
|
37
|
+
end
|
38
|
+
else
|
39
|
+
self.open_temporary
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Kernel
|
45
|
+
@@open = self.method(:open)
|
46
|
+
|
47
|
+
# If non-zero numbers of args are passed, works as it ought.
|
48
|
+
# otherwise creates and opens a temporay file.
|
49
|
+
def open(*argv, &block)
|
50
|
+
if argv.size.nonzero?
|
51
|
+
@@open.call(*argv, &block)
|
52
|
+
elsif block_given?
|
53
|
+
begin
|
54
|
+
f = self.open_temporary
|
55
|
+
yield f
|
56
|
+
ensure
|
57
|
+
f.close
|
58
|
+
end
|
59
|
+
else
|
60
|
+
File.open
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Local Variables:
|
67
|
+
# mode: ruby
|
68
|
+
# coding: utf-8-unix
|
69
|
+
# indent-tabs-mode: t
|
70
|
+
# tab-width: 3
|
71
|
+
# ruby-indent-level: 3
|
72
|
+
# fill-column: 79
|
73
|
+
# default-justification: full
|
74
|
+
# End:
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "open-temporary"
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Urabe, Shyouhei"]
|
12
|
+
s.date = "2012-09-05"
|
13
|
+
s.description = "A variation of tempfile standard lib, that actually creates a File instance."
|
14
|
+
s.email = "shyouhei@ruby-lang.org"
|
15
|
+
s.extensions = ["ext/open_temporary/extconf.rb"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"ext/open_temporary/.gitignore",
|
30
|
+
"ext/open_temporary/extconf.rb",
|
31
|
+
"ext/open_temporary/open_temporary.c",
|
32
|
+
"lib/open-temporary.rb",
|
33
|
+
"open-temporary.gemspec",
|
34
|
+
"spec/open-temporary_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = "http://github.com/shyouhei/open-temporary"
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = "1.8.22"
|
41
|
+
s.summary = "A variant of Tempfile that makes File instead"
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<rake>, ["~> 0.9.0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
49
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.2.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
53
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rake>, ["~> 0.9.0"])
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
57
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
58
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
61
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rake>, ["~> 0.9.0"])
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
66
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
67
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
70
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included
|
11
|
+
# in all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'spec_helper'
|
22
|
+
|
23
|
+
describe File do
|
24
|
+
describe "#open" do
|
25
|
+
context "when passed nothing" do
|
26
|
+
subject { File.open }
|
27
|
+
it { should be_kind_of(File) }
|
28
|
+
its(:size) { should be_zero }
|
29
|
+
its(:path) { File.exist?(subject).should be_false }
|
30
|
+
it("can be written") { expect { subject.write("foo") }.to_not raise_error }
|
31
|
+
it("can be seeked") { expect { subject.rewind }.to_not raise_error }
|
32
|
+
it("can be read") { expect { subject.read }.to_not raise_error }
|
33
|
+
context "when passed block" do
|
34
|
+
it "yields" do
|
35
|
+
ex = Exception.new
|
36
|
+
expect do
|
37
|
+
File.open do |f|
|
38
|
+
f.should be_kind_of(File)
|
39
|
+
raise ex
|
40
|
+
end
|
41
|
+
end.to raise_exception(ex)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context "when passed something" do
|
46
|
+
subject { File.open IO::NULL }
|
47
|
+
it { should be_kind_of(File) }
|
48
|
+
its(:path) { File.exist?(subject).should be_true }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Local Variables:
|
55
|
+
# mode: ruby
|
56
|
+
# coding: utf-8-unix
|
57
|
+
# indent-tabs-mode: t
|
58
|
+
# tab-width: 3
|
59
|
+
# ruby-indent-level: 3
|
60
|
+
# fill-column: 79
|
61
|
+
# default-justification: full
|
62
|
+
# End:
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright (c) 2012 Urabe, Shyouhei
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included
|
11
|
+
# in all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'ext', 'open_temporary'))
|
22
|
+
require 'rspec'
|
23
|
+
require 'simplecov'
|
24
|
+
SimpleCov.start
|
25
|
+
require_relative '../lib/open-temporary'
|
26
|
+
|
27
|
+
# Requires supporting files with custom matchers and macros, etc,
|
28
|
+
# in ./support/ and its subdirectories.
|
29
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Local Variables:
|
37
|
+
# mode: ruby
|
38
|
+
# coding: utf-8-unix
|
39
|
+
# indent-tabs-mode: t
|
40
|
+
# tab-width: 3
|
41
|
+
# ruby-indent-level: 3
|
42
|
+
# fill-column: 79
|
43
|
+
# default-justification: full
|
44
|
+
# End:
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open-temporary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Urabe, Shyouhei
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.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: 2.8.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.7'
|
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.7'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
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: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.2.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: 1.2.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.4
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simplecov
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: A variation of tempfile standard lib, that actually creates a File instance.
|
127
|
+
email: shyouhei@ruby-lang.org
|
128
|
+
executables: []
|
129
|
+
extensions:
|
130
|
+
- ext/open_temporary/extconf.rb
|
131
|
+
extra_rdoc_files:
|
132
|
+
- LICENSE.txt
|
133
|
+
- README.rdoc
|
134
|
+
files:
|
135
|
+
- .document
|
136
|
+
- .rspec
|
137
|
+
- Gemfile
|
138
|
+
- Gemfile.lock
|
139
|
+
- LICENSE.txt
|
140
|
+
- README.rdoc
|
141
|
+
- Rakefile
|
142
|
+
- VERSION
|
143
|
+
- ext/open_temporary/.gitignore
|
144
|
+
- ext/open_temporary/extconf.rb
|
145
|
+
- ext/open_temporary/open_temporary.c
|
146
|
+
- lib/open-temporary.rb
|
147
|
+
- open-temporary.gemspec
|
148
|
+
- spec/open-temporary_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
homepage: http://github.com/shyouhei/open-temporary
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
hash: 956200431
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ! '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 1.8.22
|
175
|
+
signing_key:
|
176
|
+
specification_version: 3
|
177
|
+
summary: A variant of Tempfile that makes File instead
|
178
|
+
test_files: []
|