spotlight 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/spotlight/query.rb +13 -0
- data/spec/spotlight_query_spec.rb +12 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -18,6 +18,10 @@ Description goes here.
|
|
18
18
|
|
19
19
|
query = Spotlight::Query.from_saved_search('foo.savedSearch')
|
20
20
|
|
21
|
+
=== Creates .savedSearch
|
22
|
+
|
23
|
+
query.to_saved_search('bar.savedSearch')
|
24
|
+
|
21
25
|
=== Gets the metadata attribute for the specified file
|
22
26
|
|
23
27
|
item = Spotlight::Item.new('/Users/youpy/foo')
|
data/lib/spotlight/query.rb
CHANGED
@@ -23,5 +23,18 @@ module Spotlight
|
|
23
23
|
@md_query.set_search_scopes(@scopes)
|
24
24
|
@md_query.execute
|
25
25
|
end
|
26
|
+
|
27
|
+
def to_saved_search(filename)
|
28
|
+
obj = {
|
29
|
+
'RawQuery' => query_string,
|
30
|
+
'SearchCriteria' => {
|
31
|
+
'FXScopeArrayOfPaths' => scopes
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
File.open(filename, 'w') do |file|
|
36
|
+
file.write(obj.to_plist)
|
37
|
+
end
|
38
|
+
end
|
26
39
|
end
|
27
40
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
describe Spotlight::Query do
|
4
5
|
before do
|
@@ -11,6 +12,17 @@ describe Spotlight::Query do
|
|
11
12
|
query.scopes.should eql(['kMDQueryScopeComputer'])
|
12
13
|
end
|
13
14
|
|
15
|
+
it "should create saved search from query" do
|
16
|
+
tempfile = Tempfile.new('saved_search')
|
17
|
+
|
18
|
+
@query.scopes << '/foo/bar'
|
19
|
+
@query.to_saved_search(tempfile.path)
|
20
|
+
|
21
|
+
plist = Plist::parse_xml(tempfile.path)
|
22
|
+
plist['RawQuery'].should eql('kMDItemDisplayName = "spotlight_query_spec.rb"')
|
23
|
+
plist['SearchCriteria']['FXScopeArrayOfPaths'].should eql(['/foo/bar'])
|
24
|
+
end
|
25
|
+
|
14
26
|
it "should have query string" do
|
15
27
|
@query.query_string.should eql('kMDItemDisplayName = "spotlight_query_spec.rb"')
|
16
28
|
end
|