tempfile_for 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.1
6
+
7
+ install:
8
+ - "travis_retry bundle install"
9
+
10
+ script: "bundle exec rake test"
11
+
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ [![Build Status](https://secure.travis-ci.org/mrkamel/tempfile_for.png?branch=master)](http://travis-ci.org/mrkamel/tempfile_for)
3
+ [![Code Climate](https://codeclimate.com/github/mrkamel/tempfile_for.png)](https://codeclimate.com/github/mrkamel/tempfile_for)
4
+ [![Dependency Status](https://gemnasium.com/mrkamel/tempfile_for.png?travis)](https://gemnasium.com/mrkamel/tempfile_for)
5
+
2
6
  # TempfileFor
3
7
 
4
8
  Easily create temporary files for in-memory data, modify the file, and get the
@@ -90,6 +94,17 @@ Tempfile.blank(:encoding => Encoding::BINARY) { ... }
90
94
 
91
95
  will return a string encoded as binary.
92
96
 
97
+ ## Suffix
98
+
99
+ You can pass a `:suffix => "..."` option to all methods, such that
100
+
101
+ ```ruby
102
+ Tempfile.for("data", :suffix => ".jpg")
103
+ Tempfile.blank(:suffix => ".jpg") { ... }
104
+ ```
105
+
106
+ will create tempfiles having a `.jpg` suffix.
107
+
93
108
  ## Contributing
94
109
 
95
110
  1. Fork it
data/lib/tempfile_for.rb CHANGED
@@ -14,15 +14,13 @@ class Tempfile
14
14
  end
15
15
 
16
16
  def self.blank(options = {})
17
- encoding = options[:encoding]
18
-
19
- tempfile = TempfileFor::Tempfile.open("tempfile", :encoding => encoding)
17
+ tempfile = TempfileFor::Tempfile.build(options)
20
18
 
21
19
  yield tempfile if block_given?
22
20
 
23
21
  tempfile.flush
24
22
 
25
- options[:read] != false ? File.read(tempfile.path, :encoding => encoding) : tempfile.copy(:encoding => encoding)
23
+ options[:read] != false ? File.read(tempfile.path, :encoding => options[:encoding]) : tempfile.copy(options)
26
24
  ensure
27
25
  tempfile.close!
28
26
  end
@@ -3,12 +3,14 @@ require "tempfile"
3
3
 
4
4
  module TempfileFor
5
5
  class Tempfile < ::Tempfile
6
- def copy(options = {})
7
- encoding = options[:encoding]
6
+ def self.build(options = {})
7
+ open options[:suffix] ? ["tempfile", options[:suffix]] : "tempfile", :encoding => options[:encoding]
8
+ end
8
9
 
9
- tempfile = self.class.open("tempfile", :encoding => encoding)
10
+ def copy(options = {})
11
+ tempfile = self.class.build(options)
10
12
 
11
- File.open(path, :encoding => encoding) { |stream| tempfile.write_ext stream }
13
+ File.open(path, :encoding => options[:encoding]) { |stream| tempfile.write_ext stream }
12
14
 
13
15
  tempfile.rewind
14
16
  tempfile
@@ -1,3 +1,3 @@
1
1
  module TempfileFor
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/tempfile_for.gemspec CHANGED
@@ -18,5 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_development_dependency "rake"
21
+ s.add_development_dependency "minitest"
22
+ s.add_development_dependency "bundler"
21
23
  end
22
24
 
@@ -27,5 +27,13 @@ class TempfileFor::TemfileTest < Minitest::Test
27
27
 
28
28
  assert_equal "test", tempfile.read
29
29
  end
30
+
31
+ def test_build
32
+ assert Dir["/tmp/*.jpg"].empty?
33
+
34
+ assert_equal Encoding::ISO_8859_1, TempfileFor::Tempfile.build(:suffix => ".jpg", :encoding => Encoding::ISO_8859_1).external_encoding
35
+
36
+ refute Dir["/tmp/*.jpg"].empty?
37
+ end
30
38
  end
31
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tempfile_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-14 00:00:00.000000000 Z
12
+ date: 2014-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '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: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
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'
30
62
  description: Create temporary files for in-memory data
31
63
  email:
32
64
  - vetter@flakks.com
@@ -35,6 +67,7 @@ extensions: []
35
67
  extra_rdoc_files: []
36
68
  files:
37
69
  - .gitignore
70
+ - .travis.yml
38
71
  - Gemfile
39
72
  - LICENSE
40
73
  - README.md