fspath-mac 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/.travis.yml +2 -2
- data/ext/fspath/mac/{finder_label_number.c → ext.m} +36 -6
- data/ext/fspath/mac/extconf.rb +2 -2
- data/fspath-mac.gemspec +2 -2
- data/lib/fspath/mac.rb +3 -3
- data/spec/fspath/mac_spec.rb +27 -23
- data/spec/spec_helper.rb +1 -1
- metadata +8 -9
- data/TODO +0 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGYwYzQwZjNkNTQ5MGRjZDNjZTE0OWUyNWVmOWRmZTNjYmRkYjAwNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
ODgyMWYwZDBkMDU2OWQ1ZDI0YjFlMTlkOGZjM2YxOGVjMWRmYTcwMA==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTc2ZDQ5OTNjZjdiYThhZWU0OWVkM2ZjMGE5MGZkMzM1MTdkYzQ3MTVmZjdh
|
10
|
+
MDE2N2JhNWNkZGIzNjBkMjg4MGI3NmJhYWU2ODQ2MjdmMDU4N2Y1MGM4MGY3
|
11
|
+
MmU5MWI1N2YzOTQ5MTRlMmNkMWJkNWJiZDU1MDA3MjdmZGFiZTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzIxYmM3ZmI1YjFkMjBkNjM3YjFkOTJhNmE4NzM4OWVmYzMyNzE2YWVlZjU1
|
14
|
+
OTNhNjE4ZjY3MWJhZTk4YjE0MzIzZTcwYTlhYjA4MTVkNjA3OTRmYjdiNmU3
|
15
|
+
ZjcwNjE4ODIyMTg5NzEzOTFkYTkxNjgzMTEwYmIxYmI1ZjQ0ZWU=
|
data/.travis.yml
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
+
#include <AppKit/AppKit.h>
|
2
3
|
#include <CoreServices/CoreServices.h>
|
3
4
|
|
4
|
-
|
5
|
-
VALUE path = rb_iv_get(
|
5
|
+
CFStringRef get_path(VALUE self){
|
6
|
+
VALUE path = rb_iv_get(self, "@path");
|
6
7
|
char *pathStr = StringValueCStr(path);
|
7
|
-
|
8
8
|
CFStringRef pathRef = CFStringCreateWithCString(NULL, pathStr, kCFStringEncodingUTF8);
|
9
|
+
|
9
10
|
if (!pathRef) {
|
10
11
|
rb_raise(rb_eRuntimeError, "Can't convert path");
|
11
12
|
}
|
12
13
|
|
14
|
+
return pathRef;
|
15
|
+
}
|
16
|
+
|
17
|
+
CFURLRef get_url(VALUE self){
|
18
|
+
CFStringRef pathRef = get_path(self);
|
13
19
|
CFURLRef urlRef = CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, false);
|
14
20
|
CFRelease(pathRef);
|
21
|
+
|
15
22
|
if (!urlRef) {
|
16
23
|
rb_raise(rb_eRuntimeError, "Can't initialize url for path");
|
17
24
|
}
|
@@ -35,7 +42,7 @@ void raise_cf_error(CFErrorRef errorRef){
|
|
35
42
|
}
|
36
43
|
|
37
44
|
static VALUE finder_label_number_get(VALUE self){
|
38
|
-
CFURLRef urlRef =
|
45
|
+
CFURLRef urlRef = get_url(self);
|
39
46
|
|
40
47
|
CFErrorRef errorRef;
|
41
48
|
CFNumberRef labelNumberRef;
|
@@ -63,7 +70,7 @@ static VALUE finder_label_number_set(VALUE self, VALUE labelNumber){
|
|
63
70
|
rb_raise(rb_eArgError, "label number can be in range 0..7");
|
64
71
|
}
|
65
72
|
|
66
|
-
CFURLRef urlRef =
|
73
|
+
CFURLRef urlRef = get_url(self);
|
67
74
|
|
68
75
|
CFNumberRef labelNumberRef = CFNumberCreate(NULL, kCFNumberSInt32Type, &labelNumberValue);
|
69
76
|
|
@@ -79,9 +86,32 @@ static VALUE finder_label_number_set(VALUE self, VALUE labelNumber){
|
|
79
86
|
return Qnil;
|
80
87
|
}
|
81
88
|
|
82
|
-
|
89
|
+
static VALUE move_to_trash(VALUE self){
|
90
|
+
CFStringRef pathRef = get_path(self);
|
91
|
+
NSString *path = (NSString *)pathRef;
|
92
|
+
|
93
|
+
NSString *dir = [path stringByDeletingLastPathComponent];
|
94
|
+
NSString *name = [path lastPathComponent];
|
95
|
+
NSArray *names = [NSArray arrayWithObject:name];
|
96
|
+
BOOL success = [[NSWorkspace sharedWorkspace]
|
97
|
+
performFileOperation:NSWorkspaceRecycleOperation
|
98
|
+
source:dir
|
99
|
+
destination:@""
|
100
|
+
files:names
|
101
|
+
tag:nil];
|
102
|
+
[names release];
|
103
|
+
[name release];
|
104
|
+
[dir release];
|
105
|
+
|
106
|
+
CFRelease(pathRef);
|
107
|
+
|
108
|
+
return success ? Qtrue : Qfalse;
|
109
|
+
}
|
110
|
+
|
111
|
+
void Init_ext() {
|
83
112
|
VALUE cFSPath = rb_const_get(rb_cObject, rb_intern("FSPath"));
|
84
113
|
VALUE mMac = rb_const_get(cFSPath, rb_intern("Mac"));
|
85
114
|
rb_define_private_method(mMac, "finder_label_number", finder_label_number_get, 0);
|
86
115
|
rb_define_private_method(mMac, "finder_label_number=", finder_label_number_set, 1);
|
116
|
+
rb_define_method(mMac, "move_to_trash", move_to_trash, 0);
|
87
117
|
}
|
data/ext/fspath/mac/extconf.rb
CHANGED
data/fspath-mac.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'fspath-mac'
|
5
|
-
s.version = '3.0
|
5
|
+
s.version = '3.1.0'
|
6
6
|
s.summary = %q{FSPath methods for mac (move_to_trash, color labeling, spotlight comments, …)}
|
7
7
|
s.homepage = "http://github.com/toy/#{s.name}"
|
8
8
|
s.authors = ['Ivan Kuchin']
|
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_paths = %w[lib]
|
18
18
|
|
19
19
|
s.add_dependency 'fspath', '~> 2.0'
|
20
|
-
s.add_development_dependency 'rspec'
|
20
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
21
21
|
end
|
data/lib/fspath/mac.rb
CHANGED
@@ -3,9 +3,9 @@ require 'shellwords'
|
|
3
3
|
|
4
4
|
class FSPath
|
5
5
|
module Mac
|
6
|
-
# Move to trash
|
6
|
+
# Move to trash
|
7
7
|
def move_to_trash
|
8
|
-
|
8
|
+
# actual implementation in extension
|
9
9
|
end
|
10
10
|
|
11
11
|
FINDER_LABEL_COLORS = [nil, :grey, :green, :purple, :blue, :yellow, :red, :orange].freeze
|
@@ -49,4 +49,4 @@ class FSPath
|
|
49
49
|
include Mac
|
50
50
|
end
|
51
51
|
|
52
|
-
require 'fspath/mac/
|
52
|
+
require 'fspath/mac/ext'
|
data/spec/fspath/mac_spec.rb
CHANGED
@@ -4,12 +4,16 @@ require 'fspath/mac'
|
|
4
4
|
describe FSPath::Mac do
|
5
5
|
describe "mac related" do
|
6
6
|
describe "move_to_trash" do
|
7
|
-
it "should
|
8
|
-
@path = FSPath
|
7
|
+
it "should remove file but not unlink it" do
|
8
|
+
@path = FSPath.temp_file_path
|
9
|
+
@link = FSPath.temp_file_path
|
10
|
+
@link.unlink
|
11
|
+
@link.make_link(@path)
|
9
12
|
|
10
|
-
@path.
|
13
|
+
expect(@path.move_to_trash).to be true
|
11
14
|
|
12
|
-
@path.
|
15
|
+
expect(@path).not_to exist
|
16
|
+
expect(@link.stat.nlink).to eq(2)
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
@@ -18,7 +22,7 @@ describe FSPath::Mac do
|
|
18
22
|
it "should call finder_label_number" do
|
19
23
|
@path = FSPath('to_label')
|
20
24
|
|
21
|
-
@path.
|
25
|
+
expect(@path).to receive(:finder_label_number).and_return(0)
|
22
26
|
|
23
27
|
@path.finder_label
|
24
28
|
end
|
@@ -27,8 +31,8 @@ describe FSPath::Mac do
|
|
27
31
|
@path = FSPath('to_label')
|
28
32
|
|
29
33
|
FSPath::FINDER_LABEL_COLORS.each_with_index do |label, index|
|
30
|
-
@path.
|
31
|
-
@path.finder_label.
|
34
|
+
allow(@path).to receive(:finder_label_number).and_return(index)
|
35
|
+
expect(@path.finder_label).to eq(label)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -37,7 +41,7 @@ describe FSPath::Mac do
|
|
37
41
|
it "should call finder_label_number=" do
|
38
42
|
@path = FSPath('to_label')
|
39
43
|
|
40
|
-
@path.
|
44
|
+
expect(@path).to receive(:finder_label_number=)
|
41
45
|
|
42
46
|
@path.finder_label = nil
|
43
47
|
end
|
@@ -49,7 +53,7 @@ describe FSPath::Mac do
|
|
49
53
|
|
50
54
|
it "should call label_index.set with apporitate index" do
|
51
55
|
FSPath::FINDER_LABEL_COLORS.each_with_index do |label, index|
|
52
|
-
@path.
|
56
|
+
expect(@path).to receive(:finder_label_number=).with(index).ordered
|
53
57
|
@path.finder_label = label
|
54
58
|
end
|
55
59
|
end
|
@@ -57,21 +61,21 @@ describe FSPath::Mac do
|
|
57
61
|
it "should accept aliases" do
|
58
62
|
FSPath::FINDER_LABEL_COLOR_ALIASES.each do |label_alias, label|
|
59
63
|
index = FSPath::FINDER_LABEL_COLORS.index(label)
|
60
|
-
@path.
|
64
|
+
expect(@path).to receive(:finder_label_number=).with(index).ordered
|
61
65
|
@path.finder_label = label_alias
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
69
|
it "should set to none when called with nil or false" do
|
66
|
-
@path.
|
70
|
+
expect(@path).to receive(:finder_label_number=).with(0).ordered
|
67
71
|
@path.finder_label = nil
|
68
72
|
end
|
69
73
|
|
70
74
|
it "should raise when called with something else" do
|
71
75
|
[true, :shitty, 'hello'].each do |label|
|
72
|
-
|
76
|
+
expect do
|
73
77
|
@path.finder_label = label
|
74
|
-
end.
|
78
|
+
end.to raise_error("Unknown label #{label.inspect}")
|
75
79
|
end
|
76
80
|
end
|
77
81
|
end
|
@@ -94,9 +98,9 @@ describe FSPath::Mac do
|
|
94
98
|
mac_finder_alias_colors = [nil, :orange, :red, :yellow, :blue, :purple, :green, :grey]
|
95
99
|
8.times do |label_number|
|
96
100
|
@path.send(:finder_label_number=, label_number)
|
97
|
-
@path.send(:finder_label_number).
|
101
|
+
expect(@path.send(:finder_label_number)).to eq(label_number)
|
98
102
|
color = mac_finder_alias_colors[label_index_through_osascript(@path)]
|
99
|
-
FSPath::Mac::FINDER_LABEL_COLORS.index(color).
|
103
|
+
expect(FSPath::Mac::FINDER_LABEL_COLORS.index(color)).to eq(label_number)
|
100
104
|
end
|
101
105
|
end
|
102
106
|
end
|
@@ -107,9 +111,9 @@ describe FSPath::Mac do
|
|
107
111
|
it "should call comment get using with_argv_tell_finder_to" do
|
108
112
|
@path = FSPath(__FILE__)
|
109
113
|
|
110
|
-
@path.
|
114
|
+
expect(@path).to receive(:with_argv_tell_finder_to).with('get comment of (POSIX file (item 1 of argv) as alias)')
|
111
115
|
|
112
|
-
@path.spotlight_comment.
|
116
|
+
expect(@path.spotlight_comment).to eq(@comment_text)
|
113
117
|
end
|
114
118
|
end
|
115
119
|
|
@@ -117,7 +121,7 @@ describe FSPath::Mac do
|
|
117
121
|
it "should call comment set using with_argv_tell_finder_to" do
|
118
122
|
@path = FSPath(__FILE__)
|
119
123
|
|
120
|
-
@path.
|
124
|
+
expect(@path).to receive(:with_argv_tell_finder_to).with('set comment of (POSIX file (item 1 of argv) as alias) to (item 2 of argv)', 'abc')
|
121
125
|
|
122
126
|
@path.spotlight_comment = 'abc'
|
123
127
|
end
|
@@ -127,19 +131,19 @@ describe FSPath::Mac do
|
|
127
131
|
it "should call comment get using with_argv_tell_finder_to" do
|
128
132
|
@path = FSPath.temp_file_path
|
129
133
|
|
130
|
-
@path.spotlight_comment.
|
134
|
+
expect(@path.spotlight_comment).to eq('')
|
131
135
|
|
132
136
|
@path.spotlight_comment = 'abc'
|
133
|
-
@path.spotlight_comment.
|
137
|
+
expect(@path.spotlight_comment).to eq('abc')
|
134
138
|
|
135
139
|
@path.spotlight_comment = 1
|
136
|
-
@path.spotlight_comment.
|
140
|
+
expect(@path.spotlight_comment).to eq('1')
|
137
141
|
|
138
142
|
@path.spotlight_comment = "def\nghi"
|
139
|
-
@path.spotlight_comment.
|
143
|
+
expect(@path.spotlight_comment).to eq("def\nghi")
|
140
144
|
|
141
145
|
@path.spotlight_comment = nil
|
142
|
-
@path.spotlight_comment.
|
146
|
+
expect(@path.spotlight_comment).to eq('')
|
143
147
|
end
|
144
148
|
end
|
145
149
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Dir.chdir File.
|
1
|
+
Dir.chdir File.expand_path('../..', __FILE__) do # chdir to project root
|
2
2
|
Dir['ext/**/extconf.rb'].each do |extconf|
|
3
3
|
Dir.chdir(File.dirname(extconf)) do
|
4
4
|
system('ruby extconf.rb') && system('make') or abort "failed compiling #{extconf}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fspath-mac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fspath
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '3.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '3.0'
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
executables: []
|
@@ -50,9 +50,8 @@ files:
|
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE.txt
|
52
52
|
- README.markdown
|
53
|
-
-
|
53
|
+
- ext/fspath/mac/ext.m
|
54
54
|
- ext/fspath/mac/extconf.rb
|
55
|
-
- ext/fspath/mac/finder_label_number.c
|
56
55
|
- fspath-mac.gemspec
|
57
56
|
- lib/fspath/mac.rb
|
58
57
|
- spec/fspath/mac_spec.rb
|
@@ -77,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
76
|
version: '0'
|
78
77
|
requirements: []
|
79
78
|
rubyforge_project: fspath-mac
|
80
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.4.1
|
81
80
|
signing_key:
|
82
81
|
specification_version: 4
|
83
82
|
summary: FSPath methods for mac (move_to_trash, color labeling, spotlight comments,
|