fspath-mac 3.1.2 → 3.2.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NWQzMDU4MWVlNDU2OGVlNzU4MmViNzlhODNjZTQ1OWE1NzZhMzI3MA==
5
- data.tar.gz: !binary |-
6
- NDY2MzQ4NGJkMjY1M2JkMzlhNmMzYmZmMTgwNzMwMmRkM2Q5NTM3MA==
2
+ SHA256:
3
+ metadata.gz: b4f31c6128cb217d68a3515a0239ef84d9e1b2f92f84a029f1380000a21b698f
4
+ data.tar.gz: 23f50da059db2274c3a5453dc748bd35a1bce096d38c4143da3d91ea1ba2ead7
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NzFkNDk2NGY5ZTNkMGVhN2VjYTg4NjA0MDU2ZWVhZTEzMDJkMTNlMzI4ODBm
10
- ZGJhYTQ0MDNmNzA3YjYzNTliNGIyNjhmYmYwNjBmOTU4YWI2N2Q0YzM5NmFl
11
- OGZiNDRlYjU4ODI1NmYyMjc1ZTk3ODFjYzcwMjcyMWQzNmRiNjQ=
12
- data.tar.gz: !binary |-
13
- ZTVlZWI0ZWFlMmQxMzYzM2U1ZDkwYWZiOGNkMDVlMGM2MGQ4OTAzM2RhYzRj
14
- N2I1MzA4OTYwMGFmYjE4MTg2ZDU3ZWU2NzIwMjA2OTBjMWFjY2NiZDdkY2Y1
15
- MDI2MGY1NzkwNjAwNDk5OGVmM2U3ZWYyMTY2MjRiNDYzYWYyMWQ=
6
+ metadata.gz: 6df521685cea142e7d6d6b903b86f3425dcb32cad597fd957252fc1c74c53d189fcaa9ee3227a16656d2e5d23e2d38f6074f6bc1c9361ccffc2b902fd8cf1c94
7
+ data.tar.gz: 26381bf3d49cc0d8945b14be747af7a6ae634e6a74e7cc972b62585bd1733cc57c47a099e785547feb90bdecb917af1afc61d37c661d88518033400804f99a9c
@@ -1,8 +1,13 @@
1
- language:
2
- - objective-c
3
- - ruby
1
+ os: osx
2
+ language: ruby
4
3
  rvm:
5
- - '1.9'
6
- - '2.0'
7
- - '2.1'
4
+ - default
5
+ - '2.3.7'
6
+ - '2.4.4'
7
+ - '2.5.1'
8
8
  script: bundle exec rspec
9
+ matrix:
10
+ include:
11
+ - env: CHECK_RUBIES=✓
12
+ rvm: '2.4.4'
13
+ script: bundle exec travis_check_rubies
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ if RUBY_VERSION >= '2.0'
6
+ gem 'travis_check_rubies', '~> 0.2'
7
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2016 Ivan Kuchin
1
+ Copyright (c) 2010-2018 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -28,4 +28,4 @@ Set spotlight comment:
28
28
 
29
29
  ## Copyright
30
30
 
31
- Copyright (c) 2010-2016 Ivan Kuchin. See LICENSE.txt for details.
31
+ Copyright (c) 2010-2018 Ivan Kuchin. See LICENSE.txt for details.
@@ -1,6 +1,7 @@
1
1
  #include "ruby.h"
2
2
  #include <AppKit/AppKit.h>
3
3
  #include <CoreServices/CoreServices.h>
4
+ #include <Carbon/Carbon.h>
4
5
 
5
6
  CFStringRef get_path(VALUE self){
6
7
  VALUE path = rb_iv_get(self, "@path");
@@ -28,17 +29,18 @@ CFURLRef get_url(VALUE self){
28
29
 
29
30
  void raise_cf_error(CFErrorRef errorRef){
30
31
  CFStringRef errorDescriptionRef = CFErrorCopyDescription(errorRef);
32
+ CFRelease(errorRef);
31
33
 
32
- const char *errorDescriptionC = CFStringGetCStringPtr(errorDescriptionRef, kCFStringEncodingUTF8);
33
- if (errorDescriptionC) {
34
- rb_raise(rb_eRuntimeError, "%s", errorDescriptionC);
35
- } else {
36
- CFIndex length = CFStringGetLength(errorDescriptionRef);
37
- CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
38
- char *errorDescription = (char *) malloc(maxSize);
39
- CFStringGetCString(errorDescriptionRef, errorDescription, maxSize, kCFStringEncodingUTF8);
40
- rb_raise(rb_eRuntimeError, "%s", errorDescription);
41
- }
34
+ CFIndex length = CFStringGetLength(errorDescriptionRef);
35
+ CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
36
+ char *errorDescription = (char *) malloc(maxSize);
37
+ CFStringGetCString(errorDescriptionRef, errorDescription, maxSize, kCFStringEncodingUTF8);
38
+ CFRelease(errorDescriptionRef);
39
+
40
+ VALUE message = rb_str_new_cstr(errorDescription);
41
+ free(errorDescription);
42
+
43
+ rb_exc_raise(rb_exc_new3(rb_eRuntimeError, message));
42
44
  }
43
45
 
44
46
  static VALUE finder_label_number_get(VALUE self){
@@ -86,6 +88,99 @@ static VALUE finder_label_number_set(VALUE self, VALUE labelNumber){
86
88
  return Qnil;
87
89
  }
88
90
 
91
+ static VALUE spotlight_comment_get(VALUE self){
92
+ ProcessSerialNumber psn = { 0, kCurrentProcess };
93
+ NSAppleEventDescriptor *target = [NSAppleEventDescriptor descriptorWithDescriptorType:typeProcessSerialNumber bytes:&psn length:sizeof(ProcessSerialNumber)];
94
+ NSAppleEventDescriptor *event = [NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite eventID:kASSubroutineEvent targetDescriptor:target returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
95
+
96
+ NSAppleEventDescriptor *subroutineDescriptor = [NSAppleEventDescriptor descriptorWithString:@"_get"];
97
+ [event setParamDescriptor:subroutineDescriptor forKeyword:keyASSubroutineName];
98
+
99
+ NSAppleEventDescriptor *parameters = [NSAppleEventDescriptor listDescriptor];
100
+ CFURLRef urlRef = get_url(self);
101
+ NSAppleEventDescriptor *fileUrlDescriptor = [NSAppleEventDescriptor descriptorWithFileURL:(NSURL *)urlRef];
102
+ [parameters insertDescriptor:fileUrlDescriptor atIndex:0];
103
+ [event setParamDescriptor:parameters forKeyword:keyDirectObject];
104
+
105
+ NSDictionary *errors;
106
+ NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"on _get(_path)\ntell application \"Finder\" to get comment of (_path as alias)\nend"];
107
+ NSAppleEventDescriptor *result = [script executeAppleEvent:event error:&errors];
108
+
109
+ [script release];
110
+ [event release];
111
+ [target release];
112
+ [parameters release];
113
+ [fileUrlDescriptor release];
114
+ CFRelease(urlRef);
115
+ [subroutineDescriptor release];
116
+
117
+ if (result) {
118
+ NSString *stringValue = [result stringValue];
119
+ [result release];
120
+
121
+ VALUE rbResult = rb_str_new_cstr([stringValue UTF8String]);
122
+ [stringValue release];
123
+
124
+ return rbResult;
125
+ } else {
126
+ NSString *errorsDescription = [errors description];
127
+ [errors release];
128
+
129
+ VALUE rbMessage = rb_str_new_cstr([errorsDescription UTF8String]);
130
+ [errorsDescription release];
131
+
132
+ rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rbMessage));
133
+ }
134
+ }
135
+
136
+ static VALUE spotlight_comment_set(VALUE self, VALUE commentValue){
137
+ commentValue = rb_obj_as_string(commentValue);
138
+
139
+ ProcessSerialNumber psn = { 0, kCurrentProcess };
140
+ NSAppleEventDescriptor *target = [NSAppleEventDescriptor descriptorWithDescriptorType:typeProcessSerialNumber bytes:&psn length:sizeof(ProcessSerialNumber)];
141
+ NSAppleEventDescriptor *event = [NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite eventID:kASSubroutineEvent targetDescriptor:target returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
142
+
143
+ NSAppleEventDescriptor *subroutineDescriptor = [NSAppleEventDescriptor descriptorWithString:@"_set"];
144
+ [event setParamDescriptor:subroutineDescriptor forKeyword:keyASSubroutineName];
145
+
146
+ NSAppleEventDescriptor *parameters = [NSAppleEventDescriptor listDescriptor];
147
+ CFURLRef urlRef = get_url(self);
148
+ NSAppleEventDescriptor *fileUrlDescriptor = [NSAppleEventDescriptor descriptorWithFileURL:(NSURL *)urlRef];
149
+ [parameters insertDescriptor:fileUrlDescriptor atIndex:0];
150
+ NSString *comment = [NSString stringWithCString:StringValueCStr(commentValue) encoding:NSUTF8StringEncoding];
151
+ NSAppleEventDescriptor *commentDescriptor = [NSAppleEventDescriptor descriptorWithString:comment];
152
+ [parameters insertDescriptor:commentDescriptor atIndex:0];
153
+ [event setParamDescriptor:parameters forKeyword:keyDirectObject];
154
+
155
+ NSDictionary *errors;
156
+ NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"on _set(_path, _comment)\ntell application \"Finder\" to set comment of (_path as alias) to _comment\nend"];
157
+ NSAppleEventDescriptor *result = [script executeAppleEvent:event error:&errors];
158
+
159
+ [script release];
160
+ [event release];
161
+ [target release];
162
+ [parameters release];
163
+ [commentDescriptor release];
164
+ [comment release];
165
+ [fileUrlDescriptor release];
166
+ CFRelease(urlRef);
167
+ [subroutineDescriptor release];
168
+
169
+ if (result) {
170
+ [result release];
171
+ } else {
172
+ NSString *errorsDescription = [errors description];
173
+ [errors release];
174
+
175
+ VALUE rbMessage = rb_str_new_cstr([errorsDescription UTF8String]);
176
+ [errorsDescription release];
177
+
178
+ rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rbMessage));
179
+ }
180
+
181
+ return Qnil;
182
+ }
183
+
89
184
  static VALUE move_to_trash(VALUE self){
90
185
  CFStringRef pathRef = get_path(self);
91
186
  NSString *path = (NSString *)pathRef;
@@ -113,5 +208,7 @@ void Init_ext() {
113
208
  VALUE mMac = rb_const_get(cFSPath, rb_intern("Mac"));
114
209
  rb_define_private_method(mMac, "finder_label_number", finder_label_number_get, 0);
115
210
  rb_define_private_method(mMac, "finder_label_number=", finder_label_number_set, 1);
211
+ rb_define_method(mMac, "spotlight_comment", spotlight_comment_get, 0);
212
+ rb_define_method(mMac, "spotlight_comment=", spotlight_comment_set, 1);
116
213
  rb_define_method(mMac, "move_to_trash", move_to_trash, 0);
117
214
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'fspath-mac'
5
- s.version = '3.1.2'
5
+ s.version = '3.2.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']
@@ -25,24 +25,12 @@ class FSPath
25
25
 
26
26
  # Get spotlight comment
27
27
  def spotlight_comment
28
- with_argv_tell_finder_to 'get comment of (POSIX file (item 1 of argv) as alias)'
28
+ # actual implementation in extension
29
29
  end
30
30
 
31
31
  # Set spotlight comment
32
32
  def spotlight_comment=(comment)
33
- with_argv_tell_finder_to 'set comment of (POSIX file (item 1 of argv) as alias) to (item 2 of argv)', comment.to_s
34
- end
35
-
36
- private
37
-
38
- def with_argv_tell_finder_to(command, *args)
39
- applescript = <<-APPLESCRIPT
40
- on run argv
41
- tell application "Finder" to #{command}
42
- end run
43
- APPLESCRIPT
44
- arguments = [%w[osascript], applescript.lines.map{ |line| ['-e', line.strip] }, expand_path.to_s, *args].flatten
45
- `#{arguments.shelljoin}`.chomp("\n")
33
+ # actual implementation in extension
46
34
  end
47
35
  end
48
36
 
@@ -107,44 +107,22 @@ describe FSPath::Mac do
107
107
  end
108
108
 
109
109
  describe "spotlight comments" do
110
- describe "getting" do
111
- it "should call comment get using with_argv_tell_finder_to" do
112
- @path = FSPath(__FILE__)
113
-
114
- expect(@path).to receive(:with_argv_tell_finder_to).with('get comment of (POSIX file (item 1 of argv) as alias)')
115
-
116
- expect(@path.spotlight_comment).to eq(@comment_text)
117
- end
118
- end
119
-
120
- describe "setting" do
121
- it "should call comment set using with_argv_tell_finder_to" do
122
- @path = FSPath(__FILE__)
123
-
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')
125
-
126
- @path.spotlight_comment = 'abc'
127
- end
128
- end
129
-
130
- describe "getting" do
131
- it "should call comment get using with_argv_tell_finder_to" do
132
- @path = FSPath.temp_file_path
110
+ it "sets and retrieves spotlight comment" do
111
+ @path = FSPath.temp_file_path
133
112
 
134
- expect(@path.spotlight_comment).to eq('')
113
+ expect(@path.spotlight_comment).to eq('')
135
114
 
136
- @path.spotlight_comment = 'abc'
137
- expect(@path.spotlight_comment).to eq('abc')
115
+ @path.spotlight_comment = 'abc'
116
+ expect(@path.spotlight_comment).to eq('abc')
138
117
 
139
- @path.spotlight_comment = 1
140
- expect(@path.spotlight_comment).to eq('1')
118
+ @path.spotlight_comment = 1
119
+ expect(@path.spotlight_comment).to eq('1')
141
120
 
142
- @path.spotlight_comment = "def\nghi"
143
- expect(@path.spotlight_comment).to eq("def\nghi")
121
+ @path.spotlight_comment = "def\nghi"
122
+ expect(@path.spotlight_comment).to eq("def\nghi")
144
123
 
145
- @path.spotlight_comment = nil
146
- expect(@path.spotlight_comment).to eq('')
147
- end
124
+ @path.spotlight_comment = nil
125
+ expect(@path.spotlight_comment).to eq('')
148
126
  end
149
127
  end
150
128
  end
metadata CHANGED
@@ -1,47 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fspath-mac
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.2.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: 2016-07-09 00:00:00.000000000 Z
11
+ date: 2018-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fspath
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '4'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '4'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '3.0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ~>
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
47
  description:
@@ -51,8 +51,8 @@ extensions:
51
51
  - ext/fspath/mac/extconf.rb
52
52
  extra_rdoc_files: []
53
53
  files:
54
- - .gitignore
55
- - .travis.yml
54
+ - ".gitignore"
55
+ - ".travis.yml"
56
56
  - Gemfile
57
57
  - LICENSE.txt
58
58
  - README.markdown
@@ -72,17 +72,17 @@ require_paths:
72
72
  - lib
73
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ! '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project: fspath-mac
85
- rubygems_version: 2.6.4
85
+ rubygems_version: 2.7.7
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: FSPath methods for mac (move_to_trash, color labeling, spotlight comments,
@@ -90,4 +90,3 @@ summary: FSPath methods for mac (move_to_trash, color labeling, spotlight commen
90
90
  test_files:
91
91
  - spec/fspath/mac_spec.rb
92
92
  - spec/spec_helper.rb
93
- has_rdoc: