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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mjc3OTNmODI0YzZlMTJjOTVjZGI3MjExNjg3YzAxMGNhNzM1OTA4OA==
4
+ OGYwYzQwZjNkNTQ5MGRjZDNjZTE0OWUyNWVmOWRmZTNjYmRkYjAwNw==
5
5
  data.tar.gz: !binary |-
6
- MjlkOTQ0Zjk5OWQ0ZDdhN2ZjMmUzN2U2NWY2MGU2YWEyN2IxOTU3NA==
7
- !binary "U0hBNTEy":
6
+ ODgyMWYwZDBkMDU2OWQ1ZDI0YjFlMTlkOGZjM2YxOGVjMWRmYTcwMA==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2JmMjY1YzgyYTNhZTdjOGI4OTJmMDEzMmU0OTI0NjIxNWEyNTJlNTRiNzli
10
- ODhjMzdlZmJjNDI2YmEwZmZmZDdiYzE5MjEwNjRkOTY0MmI5NjcxNTBiZmJi
11
- MjJlZmRmMWYyNDAyNTVlZmJmY2NmMzUzZDhhNTQ3ZGQ3NTYyZTQ=
9
+ YTc2ZDQ5OTNjZjdiYThhZWU0OWVkM2ZjMGE5MGZkMzM1MTdkYzQ3MTVmZjdh
10
+ MDE2N2JhNWNkZGIzNjBkMjg4MGI3NmJhYWU2ODQ2MjdmMDU4N2Y1MGM4MGY3
11
+ MmU5MWI1N2YzOTQ5MTRlMmNkMWJkNWJiZDU1MDA3MjdmZGFiZTA=
12
12
  data.tar.gz: !binary |-
13
- ZjQ2NWM1YmYzMDU2YjkzNjMyMGE0YjQ0Y2NmYzUxMTUwOGJjZDRlYTNkNTVl
14
- Zjc0YzY1ZDU1ZGNkZTFlOTlhNGQwYWZlMDc4Y2MyY2U3ODhjY2FmZTJkODQ2
15
- NjVhZTg5ZjFjYjliMWU0YjVmYTI2NThkZWVkOTdmZjU0ZDI0YzM=
13
+ MzIxYmM3ZmI1YjFkMjBkNjM3YjFkOTJhNmE4NzM4OWVmYzMyNzE2YWVlZjU1
14
+ OTNhNjE4ZjY3MWJhZTk4YjE0MzIzZTcwYTlhYjA4MTVkNjA3OTRmYjdiNmU3
15
+ ZjcwNjE4ODIyMTg5NzEzOTFkYTkxNjgzMTEwYmIxYmI1ZjQ0ZWU=
@@ -2,6 +2,6 @@ language:
2
2
  - objective-c
3
3
  - ruby
4
4
  rvm:
5
- - system
6
- - default
5
+ - 1.9.3
6
+ - 2.0.0
7
7
  script: "bundle exec rspec"
@@ -1,17 +1,24 @@
1
1
  #include "ruby.h"
2
+ #include <AppKit/AppKit.h>
2
3
  #include <CoreServices/CoreServices.h>
3
4
 
4
- CFURLRef url_for_path(VALUE fsPath){
5
- VALUE path = rb_iv_get(fsPath, "@path");
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 = url_for_path(self);
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 = url_for_path(self);
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
- void Init_finder_label_number() {
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
  }
@@ -1,5 +1,5 @@
1
1
  require 'mkmf'
2
2
 
3
- with_ldflags($LDFLAGS + ' -framework Foundation'){ true }
3
+ with_ldflags($LDFLAGS + ' -framework AppKit'){ true }
4
4
 
5
- create_makefile('fspath/mac/finder_label_number')
5
+ create_makefile('fspath/mac/ext')
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'fspath-mac'
5
- s.version = '3.0.2'
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
@@ -3,9 +3,9 @@ require 'shellwords'
3
3
 
4
4
  class FSPath
5
5
  module Mac
6
- # Move to trash using finder
6
+ # Move to trash
7
7
  def move_to_trash
8
- with_argv_tell_finder_to 'move (POSIX file (item 1 of argv) as alias) to trash'
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/finder_label_number'
52
+ require 'fspath/mac/ext'
@@ -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 call delete command using with_argv_tell_finder_to" do
8
- @path = FSPath('to_delete')
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.should_receive(:with_argv_tell_finder_to).with('move (POSIX file (item 1 of argv) as alias) to trash')
13
+ expect(@path.move_to_trash).to be true
11
14
 
12
- @path.move_to_trash
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.should_receive(:finder_label_number).and_return(0)
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.stub(:finder_label_number).and_return(index)
31
- @path.finder_label.should == 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.should_receive(:finder_label_number=)
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.should_receive(:finder_label_number=).with(index).ordered
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.should_receive(:finder_label_number=).with(index).ordered
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.should_receive(:finder_label_number=).with(0).ordered
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
- proc do
76
+ expect do
73
77
  @path.finder_label = label
74
- end.should raise_error("Unknown label #{label.inspect}")
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).should == 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).should == label_number
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.should_receive(:with_argv_tell_finder_to).with('get comment of (POSIX file (item 1 of argv) as alias)')
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.should == @comment_text
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.should_receive(:with_argv_tell_finder_to).with('set comment of (POSIX file (item 1 of argv) as alias) to (item 2 of argv)', 'abc')
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.should == ''
134
+ expect(@path.spotlight_comment).to eq('')
131
135
 
132
136
  @path.spotlight_comment = 'abc'
133
- @path.spotlight_comment.should == 'abc'
137
+ expect(@path.spotlight_comment).to eq('abc')
134
138
 
135
139
  @path.spotlight_comment = 1
136
- @path.spotlight_comment.should == '1'
140
+ expect(@path.spotlight_comment).to eq('1')
137
141
 
138
142
  @path.spotlight_comment = "def\nghi"
139
- @path.spotlight_comment.should == "def\nghi"
143
+ expect(@path.spotlight_comment).to eq("def\nghi")
140
144
 
141
145
  @path.spotlight_comment = nil
142
- @path.spotlight_comment.should == ''
146
+ expect(@path.spotlight_comment).to eq('')
143
147
  end
144
148
  end
145
149
  end
@@ -1,4 +1,4 @@
1
- Dir.chdir File.join(File.dirname(__FILE__), '..') do
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.2
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-02-14 00:00:00.000000000 Z
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
- - TODO
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.0.3
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,
data/TODO DELETED
@@ -1 +0,0 @@
1
- use NSFileManager#trashItemAtURL:resultingItemURL:error: for moving to trash