file_instance_move 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.
- data/CHANGELOG +1 -0
- data/LICENSE +18 -0
- data/README.rdoc +49 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/lib/file_instance_move.rb +41 -0
- metadata +61 -0
data/CHANGELOG
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v0.1 - Initial release
|
data/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright (c) 2009 Leif Newington
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
8
|
+
subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
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, FITNESS
|
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
= file_instance_move
|
|
2
|
+
|
|
3
|
+
== The answer to "Why can't I copy this file from an instance?"
|
|
4
|
+
|
|
5
|
+
Why can't you copy a file from an instance? I don't really know, but here's something that will allow you to do it.
|
|
6
|
+
|
|
7
|
+
== Installation
|
|
8
|
+
|
|
9
|
+
sudo gem install file_instance_move
|
|
10
|
+
|
|
11
|
+
=== Requirements
|
|
12
|
+
|
|
13
|
+
You'll need Gemcutter, thankfully it's as easy as
|
|
14
|
+
sudo gem install gemcutter
|
|
15
|
+
|
|
16
|
+
== Examples
|
|
17
|
+
|
|
18
|
+
Always do this:
|
|
19
|
+
require 'file_instance_move'
|
|
20
|
+
|
|
21
|
+
=== Copy a file
|
|
22
|
+
|
|
23
|
+
file = File.open 'file.txt'
|
|
24
|
+
...do file-y stuff here, read, write, whatever...
|
|
25
|
+
file.copy 'destination/path/file.txt'
|
|
26
|
+
file.close
|
|
27
|
+
|
|
28
|
+
If you want to continue operating on the copied file only, you can get an instance containing it by using
|
|
29
|
+
|
|
30
|
+
file = file.copy 'destination/path/file.txt'
|
|
31
|
+
|
|
32
|
+
This will also work
|
|
33
|
+
|
|
34
|
+
file.cp 'destination/path/file.txt'
|
|
35
|
+
|
|
36
|
+
=== Move a file
|
|
37
|
+
|
|
38
|
+
file = File.open 'file.txt'
|
|
39
|
+
...do file-y stuff here, read, write, whatever...
|
|
40
|
+
file.move 'file2.txt'
|
|
41
|
+
|
|
42
|
+
There is no need to call close when using .move, the file is already closed.
|
|
43
|
+
If you want to continue operating on the moved file, you can get an instance containing it by using
|
|
44
|
+
|
|
45
|
+
file = file.move 'file2.txt'
|
|
46
|
+
|
|
47
|
+
This will also work
|
|
48
|
+
|
|
49
|
+
file.mv 'file2.txt'
|
data/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'jeweler'
|
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
|
4
|
+
gemspec.name = "file_instance_move"
|
|
5
|
+
gemspec.summary = "Adds some much needed (in my mind) copying and moving of files from a File instance."
|
|
6
|
+
gemspec.description = "Adds some much needed (in my mind) copying and moving of files from a File instance."
|
|
7
|
+
gemspec.email = "leifnewington@gmail.com"
|
|
8
|
+
gemspec.homepage = "http://github.com/kyrox/file_instance_move"
|
|
9
|
+
gemspec.authors = ["Leif Newington"]
|
|
10
|
+
end
|
|
11
|
+
rescue LoadError
|
|
12
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
|
13
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
# This class adds some much needed (in my mind) copying and moving of files from a File instance.
|
|
4
|
+
|
|
5
|
+
class File
|
|
6
|
+
# write_nonblock writes to the file before close, which is what we need for copying
|
|
7
|
+
alias :write :write_nonblock
|
|
8
|
+
|
|
9
|
+
# Returns the filename of the currently open file
|
|
10
|
+
def filename
|
|
11
|
+
inspect[7..-2]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Copies the currently open file to destination, and returns a new File instance with the copied file
|
|
15
|
+
def copy destination
|
|
16
|
+
source = filename
|
|
17
|
+
FileUtils.cp source, destination
|
|
18
|
+
open destination
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Moves the currently open file, and returns a new File instance with the moved file
|
|
22
|
+
# * You do not need to call close when using this method
|
|
23
|
+
def move destination
|
|
24
|
+
source = filename
|
|
25
|
+
FileUtils.cp source, destination
|
|
26
|
+
close
|
|
27
|
+
FileUtils.rm source
|
|
28
|
+
open destination
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Alias for #copy
|
|
32
|
+
def cp destination
|
|
33
|
+
copy destination
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Alias for #move
|
|
37
|
+
def mv destination
|
|
38
|
+
move destination
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: file_instance_move
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: "0.1"
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Leif Newington
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-12-04 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Adds some much needed (in my mind) copying and moving of files from a File instance.
|
|
17
|
+
email: leifnewington@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.rdoc
|
|
25
|
+
files:
|
|
26
|
+
- CHANGELOG
|
|
27
|
+
- LICENSE
|
|
28
|
+
- README.rdoc
|
|
29
|
+
- Rakefile
|
|
30
|
+
- VERSION
|
|
31
|
+
- lib/file_instance_move.rb
|
|
32
|
+
has_rdoc: true
|
|
33
|
+
homepage: http://github.com/kyrox/file_instance_move
|
|
34
|
+
licenses: []
|
|
35
|
+
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options:
|
|
38
|
+
- --charset=UTF-8
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
version:
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: "0"
|
|
52
|
+
version:
|
|
53
|
+
requirements: []
|
|
54
|
+
|
|
55
|
+
rubyforge_project:
|
|
56
|
+
rubygems_version: 1.3.5
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 3
|
|
59
|
+
summary: Adds some much needed (in my mind) copying and moving of files from a File instance.
|
|
60
|
+
test_files: []
|
|
61
|
+
|