fspath-mac 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTQ0YjllNjljZjdmNDFkODY5ZDdlODU2OTAzY2FiYzMwZTA5MDBkZQ==
5
+ data.tar.gz: !binary |-
6
+ NGEwYWQ2NzIyYzIxYTA0OWVhYTVmNjExMGI0YjM0NzI3ZjM5N2FlYg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NTE5NTZhODUxNWY2MGY5MThhZmIwMzU2ODk3ZjQ1NDNiMzVkODEyMTI2NDU2
10
+ MjhhMmY3OWI0NDdhYWNiYmI2MzQyMDdjZjU5ZThiYTI3ZDI2ZmI4OTRlNWNj
11
+ YzVmZGJiZmZkMzcxMzNiNDlhZjVkNWQwM2EzNDc5ZWI2MmQwOTE=
12
+ data.tar.gz: !binary |-
13
+ MTUzNWQyOTliMzY2YjI0Y2VlMjNlMDYyZjgyNGQ1NWFlNjE3MzQwODIwMGY3
14
+ YzRkYmE1ZTMwYTY4MWE4OWFhMzg4YWU3YjlhYmZlMmQyMmViMTY0M2Y5Yzcw
15
+ ZjNlYzViMmE0OTE4NzYwNzc4ZmM5NTNiMDg4YWYzMjExMDE2ZjE=
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Ivan Kuchin
1
+ Copyright (c) 2010-2013 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
data/README.markdown CHANGED
@@ -26,4 +26,4 @@ Set spotlight comment:
26
26
 
27
27
  ## Copyright
28
28
 
29
- Copyright (c) 2010-2011 Ivan Kuchin. See LICENSE.txt for details.
29
+ Copyright (c) 2010-2013 Ivan Kuchin. See LICENSE.txt for details.
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 = '2.0.0'
5
+ s.version = '3.0.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,6 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = %w[lib]
18
18
 
19
19
  s.add_dependency 'fspath', '~> 2.0.0'
20
- s.add_dependency 'rb-appscript'
21
20
  s.add_development_dependency 'rspec'
22
21
  end
data/lib/fspath/mac.rb CHANGED
@@ -1,19 +1,20 @@
1
1
  require 'fspath'
2
- require 'appscript'
3
2
 
4
3
  class FSPath
5
4
  module Mac
6
5
  # Move to trash using finder
7
6
  def move_to_trash
8
- mac_finder_alias.delete
7
+ with_argv_tell_finder_to 'move (POSIX file (item 1 of argv) as alias) to trash'
9
8
  end
10
9
 
11
10
  FINDER_LABEL_COLORS = [nil, :grey, :green, :purple, :blue, :yellow, :red, :orange].freeze
12
11
  FINDER_LABEL_COLOR_ALIASES = {:gray => :grey}.freeze
12
+
13
13
  # Get finder label (one of nil, :orange, :red, :yellow, :blue, :purple, :green and :grey)
14
14
  def finder_label
15
15
  FINDER_LABEL_COLORS[finder_label_number]
16
16
  end
17
+
17
18
  # Set finder label (:grey is same as :gray, nil or false as :none)
18
19
  def finder_label=(color)
19
20
  color = FINDER_LABEL_COLOR_ALIASES[color] || color
@@ -24,32 +25,24 @@ class FSPath
24
25
 
25
26
  # Get spotlight comment
26
27
  def spotlight_comment
27
- mac_finder_alias.comment.get
28
+ with_argv_tell_finder_to 'get comment of (POSIX file (item 1 of argv) as alias)'
28
29
  end
29
30
 
30
31
  # Set spotlight comment
31
32
  def spotlight_comment=(comment)
32
- mac_finder_alias.comment.set(comment.to_s)
33
- end
34
-
35
- # MacTypes::Alias for path
36
- def mac_alias
37
- MacTypes::Alias.path(@path)
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
38
34
  end
39
35
 
40
- # MacTypes::FileURL for path
41
- def mac_file_url
42
- MacTypes::FileURL.path(@path)
43
- end
44
-
45
- # Finder item for path through mac_alias
46
- def mac_finder_alias
47
- Appscript.app('Finder').items[mac_alias]
48
- end
36
+ private
49
37
 
50
- # Finder item for path through mac_alias
51
- def mac_finder_file_url
52
- Appscript.app('Finder').items[mac_file_url]
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")
53
46
  end
54
47
  end
55
48
 
@@ -4,12 +4,10 @@ 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 on mac_finder_alias" do
7
+ it "should call delete command using with_argv_tell_finder_to" do
8
8
  @path = FSPath('to_delete')
9
- @finder_alias = mock(:finder_alias)
10
9
 
11
- @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
12
- @finder_alias.should_receive(:delete)
10
+ @path.should_receive(:with_argv_tell_finder_to).with('move (POSIX file (item 1 of argv) as alias) to trash')
13
11
 
14
12
  @path.move_to_trash
15
13
  end
@@ -80,6 +78,16 @@ describe FSPath::Mac do
80
78
  end
81
79
 
82
80
  describe "number" do
81
+ def label_index_through_osascript(path)
82
+ applescript = <<-APPLESCRIPT
83
+ on run argv
84
+ tell application "Finder" to get label index of (POSIX file (item 1 of argv) as alias)
85
+ end run
86
+ APPLESCRIPT
87
+ arguments = [%w[osascript], applescript.lines.map{ |line| ['-e', line.strip] }, path.to_s].flatten
88
+ `#{arguments.shelljoin}`.to_i
89
+ end
90
+
83
91
  it "should set label" do
84
92
  @path = FSPath.temp_file_path
85
93
 
@@ -87,7 +95,7 @@ describe FSPath::Mac do
87
95
  8.times do |label_number|
88
96
  @path.send(:finder_label_number=, label_number)
89
97
  @path.send(:finder_label_number).should == label_number
90
- color = mac_finder_alias_colors[@path.mac_finder_alias.label_index.get]
98
+ color = mac_finder_alias_colors[label_index_through_osascript(@path)]
91
99
  FSPath::Mac::FINDER_LABEL_COLORS.index(color).should == label_number
92
100
  end
93
101
  end
@@ -96,70 +104,42 @@ describe FSPath::Mac do
96
104
 
97
105
  describe "spotlight comments" do
98
106
  describe "getting" do
99
- it "should call comment.get on mac_finder_alias" do
107
+ it "should call comment get using with_argv_tell_finder_to" do
100
108
  @path = FSPath(__FILE__)
101
- @finder_alias = mock(:finder_alias)
102
- @comment = mock(:comment)
103
- @comment_text = mock(:comment_text)
104
109
 
105
- @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
106
- @finder_alias.should_receive(:comment).and_return(@comment)
107
- @comment.should_receive(:get).and_return(@comment_text)
110
+ @path.should_receive(:with_argv_tell_finder_to).with('get comment of (POSIX file (item 1 of argv) as alias)')
108
111
 
109
112
  @path.spotlight_comment.should == @comment_text
110
113
  end
111
114
  end
112
115
 
113
116
  describe "setting" do
114
- it "should call comment.set on mac_finder_alias" do
117
+ it "should call comment set using with_argv_tell_finder_to" do
115
118
  @path = FSPath(__FILE__)
116
- @finder_alias = mock(:finder_alias)
117
- @comment = mock(:comment)
118
- @comment_text = mock(:comment_text)
119
119
 
120
- @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
121
- @finder_alias.should_receive(:comment).and_return(@comment)
122
- @comment.should_receive(:set).with(@comment_text.to_s)
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')
123
121
 
124
- @path.spotlight_comment = @comment_text
122
+ @path.spotlight_comment = 'abc'
125
123
  end
126
124
  end
127
- end
128
125
 
129
- describe "appscript objects" do
130
- before do
131
- @file_path = File.expand_path(__FILE__)
132
- end
126
+ describe "getting" do
127
+ it "should call comment get using with_argv_tell_finder_to" do
128
+ @path = FSPath.temp_file_path
133
129
 
134
- describe "mac_alias" do
135
- it "should return instance of MacTypes::Alias" do
136
- FSPath(@file_path).mac_alias.should be_kind_of(MacTypes::Alias)
137
- end
130
+ @path.spotlight_comment.should == ''
138
131
 
139
- it "should point to same path" do
140
- FSPath(@file_path).mac_alias.path.should == @file_path
141
- end
142
- end
132
+ @path.spotlight_comment = 'abc'
133
+ @path.spotlight_comment.should == 'abc'
143
134
 
144
- describe "mac_file_url" do
145
- it "should return instance of MacTypes::FileURL" do
146
- FSPath(@file_path).mac_file_url.should be_kind_of(MacTypes::FileURL)
147
- end
135
+ @path.spotlight_comment = 1
136
+ @path.spotlight_comment.should == '1'
148
137
 
149
- it "should point to same path" do
150
- FSPath(@file_path).mac_file_url.path.should == @file_path
151
- end
152
- end
153
-
154
- describe "mac_finder_alias" do
155
- it "should return same ref" do
156
- FSPath(@file_path).mac_finder_alias.should == Appscript.app('Finder').items[FSPath(@file_path).mac_alias]
157
- end
158
- end
138
+ @path.spotlight_comment = "def\nghi"
139
+ @path.spotlight_comment.should == "def\nghi"
159
140
 
160
- describe "mac_finder_file_url" do
161
- it "should return same ref" do
162
- FSPath(@file_path).mac_finder_file_url.should == Appscript.app('Finder').items[FSPath(@file_path).mac_file_url]
141
+ @path.spotlight_comment = nil
142
+ @path.spotlight_comment.should == ''
163
143
  end
164
144
  end
165
145
  end
metadata CHANGED
@@ -1,75 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fspath-mac
3
- version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease:
6
- segments:
7
- - 2
8
- - 0
9
- - 0
10
- version: 2.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Ivan Kuchin
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-11-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: fspath
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
26
17
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 15
29
- segments:
30
- - 2
31
- - 0
32
- - 0
18
+ - !ruby/object:Gem::Version
33
19
  version: 2.0.0
34
20
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rb-appscript
38
21
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
48
- type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
51
28
  name: rspec
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
62
34
  type: :development
63
- version_requirements: *id003
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
64
41
  description:
65
42
  email:
66
43
  executables: []
67
-
68
- extensions:
44
+ extensions:
69
45
  - ext/fspath/mac/extconf.rb
70
46
  extra_rdoc_files: []
71
-
72
- files:
47
+ files:
73
48
  - .gitignore
74
49
  - LICENSE.txt
75
50
  - README.markdown
@@ -80,39 +55,30 @@ files:
80
55
  - spec/fspath/mac_spec.rb
81
56
  - spec/spec_helper.rb
82
57
  homepage: http://github.com/toy/fspath-mac
83
- licenses:
58
+ licenses:
84
59
  - MIT
60
+ metadata: {}
85
61
  post_install_message:
86
62
  rdoc_options: []
87
-
88
- require_paths:
63
+ require_paths:
89
64
  - lib
90
- required_ruby_version: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- hash: 3
96
- segments:
97
- - 0
98
- version: "0"
99
- required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- hash: 3
105
- segments:
106
- - 0
107
- version: "0"
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
108
75
  requirements: []
109
-
110
76
  rubyforge_project: fspath-mac
111
- rubygems_version: 1.8.24
77
+ rubygems_version: 2.0.3
112
78
  signing_key:
113
- specification_version: 3
114
- summary: "FSPath methods for mac (move_to_trash, color labeling, spotlight comments, \xE2\x80\xA6)"
115
- test_files:
79
+ specification_version: 4
80
+ summary: FSPath methods for mac (move_to_trash, color labeling, spotlight comments,
81
+ …)
82
+ test_files:
116
83
  - spec/fspath/mac_spec.rb
117
84
  - spec/spec_helper.rb
118
- has_rdoc: