fspath-mac 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ /pkg/
2
+
3
+ /doc/
4
+ /rdoc/
5
+ /.yardoc/
6
+ /coverage/
7
+
8
+ Makefile
9
+ *.o
10
+ *.bundle
11
+ /tmp/
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2011 Ivan Kuchin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # fspath
2
+
3
+ Better than Pathname
4
+
5
+ ### OS X stuff
6
+
7
+ Move to trash:
8
+
9
+ FSPath('a').move_to_trash
10
+
11
+ Get finder label (one of :none, :orange, :red, :yellow, :blue, :purple, :green and :gray):
12
+
13
+ FSPath('a').finder_label
14
+
15
+ Set finder label (:grey is same as :gray, nil or false as :none):
16
+
17
+ FSPath('a').finder_label = :red
18
+
19
+ Get spotlight comment:
20
+
21
+ FSPath('a').spotlight_comment
22
+
23
+ Set spotlight comment:
24
+
25
+ FSPath('a').spotlight_comment = 'a file'
26
+
27
+ ## Copyright
28
+
29
+ Copyright (c) 2010-2011 Ivan Kuchin. See LICENSE.txt for details.
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'fspath-mac'
5
+ s.version = '1.0.0'
6
+ s.summary = %q{FSPath methods for mac (move_to_trash, color labeling, spotlight comments, …)}
7
+ s.homepage = "http://github.com/toy/#{s.name}"
8
+ s.authors = ['Ivan Kuchin']
9
+ s.license = 'MIT'
10
+
11
+ s.rubyforge_project = s.name
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = %w[lib]
17
+
18
+ s.add_dependency 'fspath', '~> 2.0.0'
19
+ s.add_dependency 'rb-appscript'
20
+ s.add_development_dependency 'rspec'
21
+ end
@@ -0,0 +1,57 @@
1
+ require 'fspath'
2
+ require 'appscript'
3
+
4
+ class FSPath
5
+ module Mac
6
+ # Move to trash using finder
7
+ def move_to_trash
8
+ mac_finder_alias.delete
9
+ end
10
+
11
+ FINDER_LABEL_COLORS = [:none, :orange, :red, :yellow, :blue, :purple, :green, :gray].freeze
12
+ FINDER_LABEL_COLOR_ALIASES = {:grey => :gray}.freeze
13
+ # Get finder label (one of :none, :orange, :red, :yellow, :blue, :purple, :green and :gray)
14
+ def finder_label
15
+ FINDER_LABEL_COLORS[mac_finder_alias.label_index.get]
16
+ end
17
+ # Set finder label (:grey is same as :gray, nil or false as :none)
18
+ def finder_label=(color)
19
+ color = FINDER_LABEL_COLOR_ALIASES[color] || color || :none
20
+ index = FINDER_LABEL_COLORS.index(color)
21
+ raise "Unknown label #{color.inspect}" unless index
22
+ mac_finder_alias.label_index.set(index)
23
+ end
24
+
25
+ # Get spotlight comment
26
+ def spotlight_comment
27
+ mac_finder_alias.comment.get
28
+ end
29
+
30
+ # Set spotlight comment
31
+ 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)
38
+ end
39
+
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
49
+
50
+ # Finder item for path through mac_alias
51
+ def mac_finder_file_url
52
+ Appscript.app('Finder').items[mac_file_url]
53
+ end
54
+ end
55
+
56
+ include Mac
57
+ end
@@ -0,0 +1,173 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'fspath/mac'
3
+
4
+ describe FSPath::Mac do
5
+ describe "mac related" do
6
+ describe "move_to_trash" do
7
+ it "should call delete on mac_finder_alias" do
8
+ @path = FSPath('to_delete')
9
+ @finder_alias = mock(:finder_alias)
10
+
11
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
12
+ @finder_alias.should_receive(:delete)
13
+
14
+ @path.move_to_trash
15
+ end
16
+ end
17
+
18
+ describe "finder labels" do
19
+ describe "getting" do
20
+ it "should call label_index.get on mac_finder_alias" do
21
+ @path = FSPath('to_label')
22
+ @finder_alias = mock(:finder_alias)
23
+ @label_index = mock(:label_index)
24
+
25
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
26
+ @finder_alias.should_receive(:label_index).and_return(@label_index)
27
+ @label_index.should_receive(:get).and_return(0)
28
+
29
+ @path.finder_label
30
+ end
31
+
32
+ it "should return apporitate label" do
33
+ @path = FSPath('to_label')
34
+ @finder_alias = mock(:finder_alias)
35
+ @label_index = mock(:label_index)
36
+
37
+ @path.stub!(:mac_finder_alias).and_return(@finder_alias)
38
+ @finder_alias.stub!(:label_index).and_return(@label_index)
39
+
40
+ FSPath::FINDER_LABEL_COLORS.each_with_index do |label, index|
41
+ @label_index.stub!(:get).and_return(index)
42
+ @path.finder_label.should == label
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "setting" do
48
+ it "should call label_index.set on mac_finder_alias" do
49
+ @path = FSPath('to_label')
50
+ @finder_alias = mock(:finder_alias)
51
+ @label_index = mock(:label_index)
52
+
53
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
54
+ @finder_alias.should_receive(:label_index).and_return(@label_index)
55
+ @label_index.should_receive(:set)
56
+
57
+ @path.finder_label = nil
58
+ end
59
+
60
+ describe "index" do
61
+ before do
62
+ @path = FSPath('to_label')
63
+ @finder_alias = mock(:finder_alias)
64
+ @label_index = mock(:label_index)
65
+
66
+ @path.stub!(:mac_finder_alias).and_return(@finder_alias)
67
+ @finder_alias.stub!(:label_index).and_return(@label_index)
68
+ end
69
+
70
+ it "should call label_index.set with apporitate index" do
71
+ FSPath::FINDER_LABEL_COLORS.each_with_index do |label, index|
72
+ @label_index.should_receive(:set).with(index).ordered
73
+ @path.finder_label = label
74
+ end
75
+ end
76
+
77
+ it "should accept aliases" do
78
+ FSPath::FINDER_LABEL_COLOR_ALIASES.each do |label_alias, label|
79
+ index = FSPath::FINDER_LABEL_COLORS.index(label)
80
+ @label_index.should_receive(:set).with(index).ordered
81
+ @path.finder_label = label_alias
82
+ end
83
+ end
84
+
85
+ it "should set to none when called with nil or false" do
86
+ [nil, false].each do |label|
87
+ @label_index.should_receive(:set).with(0).ordered
88
+ @path.finder_label = label
89
+ end
90
+ end
91
+
92
+ it "should raise when called with something else" do
93
+ [true, :shitty, 'hello'].each do |label|
94
+ proc do
95
+ @path.finder_label = label
96
+ end.should raise_error("Unknown label #{label.inspect}")
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "spotlight comments" do
104
+ describe "getting" do
105
+ it "should call comment.get on mac_finder_alias" do
106
+ @path = FSPath(__FILE__)
107
+ @finder_alias = mock(:finder_alias)
108
+ @comment = mock(:comment)
109
+ @comment_text = mock(:comment_text)
110
+
111
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
112
+ @finder_alias.should_receive(:comment).and_return(@comment)
113
+ @comment.should_receive(:get).and_return(@comment_text)
114
+
115
+ @path.spotlight_comment.should == @comment_text
116
+ end
117
+ end
118
+
119
+ describe "setting" do
120
+ it "should call comment.set on mac_finder_alias" do
121
+ @path = FSPath(__FILE__)
122
+ @finder_alias = mock(:finder_alias)
123
+ @comment = mock(:comment)
124
+ @comment_text = mock(:comment_text)
125
+
126
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
127
+ @finder_alias.should_receive(:comment).and_return(@comment)
128
+ @comment.should_receive(:set).with(@comment_text.to_s)
129
+
130
+ @path.spotlight_comment = @comment_text
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "appscript objects" do
136
+ before do
137
+ @file_path = File.expand_path(__FILE__)
138
+ end
139
+
140
+ describe "mac_alias" do
141
+ it "should return instance of MacTypes::Alias" do
142
+ FSPath(@file_path).mac_alias.should be_kind_of(MacTypes::Alias)
143
+ end
144
+
145
+ it "should point to same path" do
146
+ FSPath(@file_path).mac_alias.path.should == @file_path
147
+ end
148
+ end
149
+
150
+ describe "mac_file_url" do
151
+ it "should return instance of MacTypes::FileURL" do
152
+ FSPath(@file_path).mac_file_url.should be_kind_of(MacTypes::FileURL)
153
+ end
154
+
155
+ it "should point to same path" do
156
+ FSPath(@file_path).mac_file_url.path.should == @file_path
157
+ end
158
+ end
159
+
160
+ describe "mac_finder_alias" do
161
+ it "should return same ref" do
162
+ FSPath(@file_path).mac_finder_alias.should == Appscript.app('Finder').items[FSPath(@file_path).mac_alias]
163
+ end
164
+ end
165
+
166
+ describe "mac_finder_file_url" do
167
+ it "should return same ref" do
168
+ FSPath(@file_path).mac_finder_file_url.should == Appscript.app('Finder').items[FSPath(@file_path).mac_file_url]
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,2 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fspath-mac
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Ivan Kuchin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: fspath
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 0
33
+ version: 2.0.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rb-appscript
38
+ 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
51
+ 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"
62
+ type: :development
63
+ version_requirements: *id003
64
+ description:
65
+ email:
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - LICENSE.txt
75
+ - README.markdown
76
+ - fspath-mac.gemspec
77
+ - lib/fspath/mac.rb
78
+ - spec/fspath/mac_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: http://github.com/toy/fspath-mac
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: fspath-mac
109
+ rubygems_version: 1.8.11
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: "FSPath methods for mac (move_to_trash, color labeling, spotlight comments, \xE2\x80\xA6)"
113
+ test_files:
114
+ - spec/fspath/mac_spec.rb
115
+ - spec/spec_helper.rb
116
+ has_rdoc: