ghaki-ext-file 2011.11.29.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Gerald Kalafut
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 in
11
+ 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
19
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,23 @@
1
+ = Ghaki Ext File - Ghaki core File extensions
2
+
3
+ Ghaki Ext File is a collection of core File extensions.
4
+
5
+ == Download
6
+
7
+ The latest version of Ghaki Ext File can be found at
8
+
9
+ * git@github.com:ghaki/ghaki-ext-file.git
10
+
11
+ == Installation
12
+
13
+ The preferred method of installing Ghaki Ext File is through its GEM file.
14
+
15
+ % [sudo] gem install ghaki-ext-file-0.0.1.gem
16
+
17
+ == License
18
+
19
+ Ghaki Ext File is released under the MIT license.
20
+
21
+ == Support
22
+
23
+ Contact mailto:gerald@kalafut.org
@@ -0,0 +1,38 @@
1
+ module Ghaki #:nodoc:
2
+ module CoreExt #:nodoc:
3
+ module File #:nodoc:
4
+
5
+ # Helpers dealing with auto-cleaning up temp files.
6
+ module WithTemp
7
+
8
+ # Calls block with temp filename then overwrites target filename if no exceptions occur.
9
+ def with_named_temp final_name
10
+ tmp_name = ::File.dirname(final_name) +
11
+ ::File::Separator + '_tmp_' + $$.to_s + '.' +
12
+ ::File.basename(final_name)
13
+ yield tmp_name
14
+ ::File.rename tmp_name, final_name
15
+ ensure
16
+ ::File.unlink tmp_name if ::File.exists?(tmp_name)
17
+ end
18
+
19
+ # Opens writable temp file, renames to proper name if no exceptions.
20
+ def with_opened_temp final_name, mode='w', perm=nil
21
+ with_named_temp final_name do |tmp_name|
22
+ ::File.open(tmp_name,mode) do |tmp_file|
23
+ yield tmp_file
24
+ end
25
+ end
26
+ end
27
+
28
+ # Simple helper for dumping a string to an output file using a temp.
29
+ def dump_via_temp data_str, final_name, mode='w', perm=nil
30
+ with_opened_temp final_name, mode, perm do |tmp_file|
31
+ tmp_file.puts data_str
32
+ end
33
+ end
34
+
35
+ ::File.extend Ghaki::CoreExt::File::WithTemp
36
+
37
+ end
38
+ end end end
@@ -0,0 +1,12 @@
1
+ require 'ghaki/core_ext/file/with_temp'
2
+
3
+ describe Ghaki::CoreExt::File::WithTemp do
4
+
5
+ context 'using extended File' do
6
+ subject { File }
7
+ it { should respond_to :with_named_temp }
8
+ it { should respond_to :with_opened_temp }
9
+ it { should respond_to :dump_via_temp }
10
+ end
11
+
12
+ end
@@ -0,0 +1,6 @@
1
+ require 'mocha'
2
+
3
+ RSpec.configure do |cfg|
4
+ cfg.mock_with :mocha
5
+ cfg.color_enabled = true
6
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghaki-ext-file
3
+ version: !ruby/object:Gem::Version
4
+ version: 2011.11.29.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gerald Kalafut
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &81920040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.4.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *81920040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &81919810 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.9.4
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *81919810
36
+ - !ruby/object:Gem::Dependency
37
+ name: mocha
38
+ requirement: &82172040 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.12
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *82172040
47
+ description: Collection of extensions for the core File class
48
+ email: gerald@kalafut.org
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README
53
+ files:
54
+ - lib/ghaki/core_ext/file/with_temp.rb
55
+ - README
56
+ - LICENSE
57
+ - spec/ghaki/core_ext/file/with_temp_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: http://github.com/ghaki
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.6
77
+ requirements: []
78
+ rubyforge_project: ghaki-ext-file
79
+ rubygems_version: 1.8.10
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Core File extensions
83
+ test_files:
84
+ - spec/ghaki/core_ext/file/with_temp_spec.rb
85
+ - spec/spec_helper.rb