debugfile 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a72d2fa8e9f06d4df7e392b225e9ebac73a8ee9
4
+ data.tar.gz: 231b40e384effc563e0c3d1659dcb9fd154155cb
5
+ SHA512:
6
+ metadata.gz: 7b88a9e14b273a2e36c3d06d247e1bd3ddda476ded33d5234f72b714dd295f97a029c9a2850c051ef1e5f7ce4aa303b3527b31532ec04ca2c540bd190d908655
7
+ data.tar.gz: 80d6ef315d4a98bd7d1f88b381a84506e3a252e80e6fd44ea95e61be17d390e0f040e4a94da70a29d83fefb91ed518fed2be3cbd3b0a12d403ef61def74e1f5e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in debugfile.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kaz3439
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 ADDED
@@ -0,0 +1,45 @@
1
+ # Debugfile
2
+
3
+ Debugfile stores temporary file for debugging, based on ruby/mri/lib/tempfile.rb
4
+
5
+ You can store files in your tmporary directory orderd by date. For example, when you file uploader fails to complete uploading process, you can get the file for debug.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'debugfile'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install debugfile
20
+
21
+ ## Usage
22
+
23
+
24
+ ```ruby
25
+ require 'debugfile'
26
+
27
+ file = Debugfile.new('for_debug', 'foo.txt')
28
+ file.path #=> e.g.: "/tmp/for_debug/20140226/e34d7899-09cf-4b46-8ef4-4f751f9ae649-foo.txt"
29
+ file.write "hello!"
30
+ file.rewind
31
+ file.read #=> "hello!"
32
+ file.close
33
+
34
+ file = Debugfile.open('for_debug', 'foo.txt') {|f| f.write "Ruby!" }
35
+ file.open
36
+ file.read #=> "Ruby!"
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/debugfile.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "debugfile"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["kaz3439"]
9
+ spec.email = ["k.hayashi.info@gmail.com"]
10
+ spec.description = %q{You can store files in your tmporary directory orderd by date}
11
+ spec.summary = %q{You can store files in your tmporary directory orderd by date. For example, when you file uploader fails to complete uploading process, you can get the file for debug.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
data/lib/debugfile.rb ADDED
@@ -0,0 +1,86 @@
1
+ #
2
+ # debugfile - store temporary file for debugging, based on ruby/mri/lib/tempfile.rb
3
+ #
4
+ #
5
+
6
+ require 'delegate'
7
+ require 'tmpdir'
8
+ require 'securerandom'
9
+
10
+ #
11
+ # == Synopsis
12
+ #
13
+ # require 'debugfile'
14
+ #
15
+ # file = Debugfile.new('for_debug', 'foo.txt')
16
+ # file.path #=> e.g.: "/tmp/for_debug/20140226/e34d7899-09cf-4b46-8ef4-4f751f9ae649-foo.txt"
17
+ # file.write "hello!"
18
+ # file.rewind
19
+ # file.read #=> "hello!"
20
+ # file.close
21
+ #
22
+ # file = Debugfile.open('for_debug', 'foo.txt') {|f| f.write "Ruby!" }
23
+ # file.open
24
+ # file.read #=> "Ruby!"
25
+ class Debugfile < DelegateClass(File)
26
+ def initialize(outdirname, outfilename, tempdir=Dir.tmpdir, opts={})
27
+ if block_given?
28
+ warn "Debugfile.new doesn't call the given block."
29
+ end
30
+
31
+ mode = File::RDWR|File::CREAT|File::EXCL
32
+ perm = 0600
33
+ if opts
34
+ mode |= opts.delete(:mode) || 0
35
+ opts[:perm] = perm
36
+ perm = nil
37
+ else
38
+ opts = perm
39
+ end
40
+
41
+ datedir = File.join(tempdir, outdirname, Time.now.strftime("%Y%m%d"))
42
+ FileUtils.mkdir_p datedir if !FileTest.exist? datedir
43
+ fulloutfilename = "#{SecureRandom.uuid}-#{outfilename}"
44
+ @path = File.join(datedir, fulloutfilename)
45
+ @debugfile = File.open(@path, mode, opts)
46
+ @mode = mode & ~(File::CREAT|File::EXCL)
47
+ perm or opts.freeze
48
+ @opts = opts
49
+ super @debugfile
50
+ end
51
+
52
+ def open
53
+ @debugfile.close if @debugfile
54
+ @debugfile = File.open(@path, @mode, @opts)
55
+ __setobj__ @debugfile
56
+ end
57
+
58
+ def close
59
+ File.unlink @debugfile if @debugfile.size == 0
60
+ begin
61
+ @debugfile.close
62
+ ensure
63
+ @debugfile = nil
64
+ end
65
+ end
66
+
67
+ def inspect
68
+ "#<#{self.class}:#{path}>"
69
+ end
70
+
71
+ class << self
72
+ def open(*args)
73
+ debugfile = new(*args)
74
+
75
+ if block_given?
76
+ begin
77
+ yield debugfile
78
+ ensure
79
+ debugfile.close
80
+ end
81
+ else
82
+ debugfile
83
+ end
84
+ end
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debugfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kaz3439
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: You can store files in your tmporary directory orderd by date
42
+ email:
43
+ - k.hayashi.info@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - debugfile.gemspec
54
+ - lib/debugfile.rb
55
+ homepage: ''
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.1.9
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: You can store files in your tmporary directory orderd by date. For example,
79
+ when you file uploader fails to complete uploading process, you can get the file
80
+ for debug.
81
+ test_files: []