motion-fileutils 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -3
- data/lib/project/motion-fileutils.rb +65 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -1,24 +1,39 @@
|
|
1
1
|
# motion-fileutils
|
2
2
|
|
3
|
-
|
3
|
+
FileUtils for RubyMotion
|
4
|
+
The aim is to implement methods in Ruby FileUtils.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
|
-
|
8
|
+
In your Gemfile:
|
8
9
|
|
10
|
+
```ruby
|
9
11
|
gem 'motion-fileutils'
|
12
|
+
```
|
10
13
|
|
11
14
|
And then execute:
|
12
15
|
|
16
|
+
```sh
|
13
17
|
$ bundle
|
18
|
+
```
|
14
19
|
|
15
20
|
Or install it yourself as:
|
16
21
|
|
22
|
+
```sh
|
17
23
|
$ gem install motion-fileutils
|
24
|
+
```
|
18
25
|
|
26
|
+
And write require line to your Rakefile
|
27
|
+
|
28
|
+
In your Rakefile
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'motion-fileutils'
|
32
|
+
```
|
33
|
+
|
34
|
+
|
19
35
|
## Usage
|
20
36
|
|
21
|
-
TODO: Write usage instructions here
|
22
37
|
|
23
38
|
## Contributing
|
24
39
|
|
@@ -27,3 +42,5 @@ TODO: Write usage instructions here
|
|
27
42
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
43
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
44
|
5. Create new Pull Request
|
45
|
+
|
46
|
+
I'm not good at English. To improve my English is welcome.
|
@@ -60,5 +60,70 @@ module Motion
|
|
60
60
|
private_module_function :mkdir_with_intermediate
|
61
61
|
|
62
62
|
|
63
|
+
def touch(list, options = {})
|
64
|
+
t = options[:mtime]
|
65
|
+
created = nocreate = options[:nocreate]
|
66
|
+
list = [list] unless list.is_a? Array
|
67
|
+
list.each do |path|
|
68
|
+
begin
|
69
|
+
File.utime(t, t, path)
|
70
|
+
rescue Errno::ENOENT
|
71
|
+
raise if created
|
72
|
+
File.open(path, 'a') {
|
73
|
+
;
|
74
|
+
}
|
75
|
+
created = true
|
76
|
+
retry if t
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
module_function :touch
|
81
|
+
|
82
|
+
|
83
|
+
def mv(src, dest, options = {})
|
84
|
+
error = Pointer.new(:object)
|
85
|
+
m = NSFileManager.defaultManager
|
86
|
+
if File.file?(dest) || !File.exists?(dest)
|
87
|
+
raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest)
|
88
|
+
rm dest if File.file?(dest)
|
89
|
+
r = m.moveItemAtPath src, toPath:dest, error:error
|
90
|
+
#p error, r unless r
|
91
|
+
else
|
92
|
+
src = [src] unless src.is_a? Array
|
93
|
+
src.each do |path|
|
94
|
+
r = m.moveItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error
|
95
|
+
#p error, r unless r
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
module_function :mv
|
100
|
+
|
101
|
+
alias move mv
|
102
|
+
module_function :move
|
103
|
+
|
104
|
+
def cp(src, dest, options = {})
|
105
|
+
error = Pointer.new(:object)
|
106
|
+
m = NSFileManager.defaultManager
|
107
|
+
if File.file?(dest) || !File.exists?(dest)
|
108
|
+
raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest)
|
109
|
+
rm dest if File.file?(dest)
|
110
|
+
r = m.copyItemAtPath src, toPath:dest, error:error
|
111
|
+
#p error, r unless r
|
112
|
+
else
|
113
|
+
src = [src] unless src.is_a? Array
|
114
|
+
src.each do |path|
|
115
|
+
r = m.copyItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error
|
116
|
+
#p error, r unless r
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
module_function :cp
|
121
|
+
|
122
|
+
=begin # NSObject#copy was already exists.
|
123
|
+
alias copy cp
|
124
|
+
module_function :copy
|
125
|
+
=end
|
126
|
+
|
127
|
+
|
63
128
|
end
|
64
129
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-fileutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -62,5 +62,5 @@ rubyforge_project:
|
|
62
62
|
rubygems_version: 1.8.25
|
63
63
|
signing_key:
|
64
64
|
specification_version: 3
|
65
|
-
summary: The aim is to implement
|
65
|
+
summary: The aim is to implement methods in Ruby FileUtils.
|
66
66
|
test_files: []
|