openmeta.rb 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
- ---
2
- SHA512:
3
- metadata.gz: ce1f732416e536da204d4f3ad1900c101e0413abc2c236919ef69035a894ef3ee7d3bccb228fb1a7220cf21307ae3a1f34d2e55c0facd4d94c48fddcfe887d8d
4
- data.tar.gz: bdc9d8a8cc54c29c0829f15215767a410540460e1da5b56e09391aa7b2ea9f6783d5f45e9d79993cc898250d9a83c499a1a87ee110e7b61a8e30cc7e256e844f
5
- SHA1:
6
- metadata.gz: 4384cc488a0106eef40bf46391de0dace21dd1c1
7
- data.tar.gz: 5d3fedc88d8e62b971a34580bfd7a12ce370f7e3
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTUyMzM1NGJjM2Q5YjgzNWY4OTE0YWEyYjc0YmExMDc4NDM4YWU5ZA==
5
+ data.tar.gz: !binary |-
6
+ YTRjOWE0OWYyNWQ4ZGZkNzE2NTYxMDVhOTViZTJiNTZmZmE2OWMxMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NTk5YWFmMzdhYTBkNjcwNzE5MTY4NzY1OGJjZDE2M2IzNDBmNzk2NzZlMTk0
10
+ MTg5ODVhOGMwZWJhODcwNGFiMGZkZmUzMTAzNDYzZGJjMWJkYjA4ZTQxNjE0
11
+ ZTkyNzRkNjIzOTY5NDMzNThkZWRmZDdlNGFiYzllNDgwMTVkZmQ=
12
+ data.tar.gz: !binary |-
13
+ ZDY3MDEyNWFhMTE4ODY5ZTRkY2M5Nzc1MDE1ZmY2MGQ5MDlhNWVhZDZkMzE1
14
+ NzQzYjE2MzcxNzdiNzY4YzMwOWY5NWJkMTZiMDA0YzdjYTQ0NDRhYzUyZjc0
15
+ ZjQxOWQxYmE2ZTY0ZDVlODYxODA1ZDczMmMzYjc5MTA4NTkwNmE=
data/.gemtest ADDED
File without changes
data/Guardfile ADDED
@@ -0,0 +1,18 @@
1
+ require 'guard/rspec'
2
+
3
+ notification :growl
4
+ # notification :terminal_notifier
5
+
6
+ group :backend do
7
+
8
+ guard 'rspec', :rvm => ["macruby"], :notification => true do
9
+
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch('spec/spec_helper.rb') { "spec" }
13
+ end
14
+
15
+ end
16
+
17
+
18
+
data/History.txt CHANGED
@@ -1,5 +1,14 @@
1
+ 1.3.0 / 2013-03-30
2
+ ==================
3
+ * [Fix]( recent tags update )
4
+ * [Improve]( spec test )
5
+ * [Remove]( Gemfile, bundler exec is not working with macruby. )
6
+
7
+ 1.2.0 / 2013-03-30
8
+ ==================
9
+ * [Improve]( polish openmeta api )
1
10
 
2
- 1.1.0 / 2013-03-27
11
+ 1.1.0 / 2013-03-27
3
12
  ==================
4
13
 
5
14
  * ! cli: support multiple files input
data/Manifest.txt CHANGED
@@ -1,6 +1,5 @@
1
1
  .ruby-version
2
- Gemfile
3
- Gemfile.lock
2
+ Guardfile
4
3
  History.txt
5
4
  Manifest.txt
6
5
  README.md
@@ -21,3 +20,5 @@ lib/openmeta/framework/OpenMeta.framework/Versions/Current
21
20
  lib/openmeta/friendly_errors.rb
22
21
  lib/openmeta/ui.rb
23
22
  lib/openmeta/version.rb
23
+ spec/openmeta_spec.rb
24
+ spec/spec_helper.rb
data/Rakefile CHANGED
@@ -12,16 +12,30 @@ Hoe.plugin :version
12
12
  Hoe.spec 'openmeta.rb' do
13
13
 
14
14
  developer('Zhao Cai', 'caizhaoff@gmail.com')
15
+ license 'GPL-3'
15
16
 
16
17
  extra_deps << ['thor', '~> 0.17.0']
18
+
19
+
20
+
21
+
22
+
23
+ extra_dev_deps << ['rspec', '>= 2.13']
24
+ extra_dev_deps << ['rake', '>= 10.0.0']
25
+ extra_dev_deps << ['hoe'] << ['hoe-gemspec'] << ['hoe-git'] << ['hoe-version'] << ['hoe-bundler']
26
+ extra_dev_deps << ['guard'] << ['guard-rspec'] << ['terminal-notifier-guard'] << ['growl']
17
27
  end
18
28
 
19
29
  %w{major minor patch}.each { |v|
20
- desc "Bump #{v.capitalize} Version and Commit"
30
+ desc "Bump #{v.capitalize} Version"
21
31
  task "bump:#{v}", [:message] => ["version:bump:#{v}"] do |t, args|
22
32
  m = args[:message] ? args[:message] : "Bump version to #{ENV["VERSION"]}"
23
33
  sh "git commit -am '#{m}'"
24
34
  end
25
35
  }
26
36
 
37
+ desc "Default Test"
38
+ task :default => [:spec] do
39
+ end
40
+
27
41
  # vim: syntax=ruby
data/lib/openmeta/cli.rb CHANGED
@@ -19,9 +19,7 @@ module Openmeta
19
19
  :type => :string ,
20
20
  :desc => "print as yaml/plist"
21
21
  def recent
22
- tags = OpenMetaPrefs.recentTags
23
-
24
- puts_to(options[:format], tags)
22
+ puts_to(options[:format], Openmeta.recent_tags)
25
23
  end
26
24
 
27
25
  desc "clone", "clone openmeta tags and rating"
@@ -1,4 +1,4 @@
1
1
  module Openmeta
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
4
4
 
data/lib/openmeta.rb CHANGED
@@ -53,11 +53,46 @@ module Openmeta
53
53
  tags
54
54
  end
55
55
 
56
- def set_tags(tags, path)
57
- e = OpenMeta.setUserTags(tags, path:File.expand_path(path))
58
- if e
56
+ def set_tags(new_tags, path)
57
+ path = File.expand_path(path)
58
+
59
+ existing_tags = OpenMeta.getUserTags(path, error:error)
60
+ if error.value
61
+ raise Openmeta::ObjCError, error.value.inspect
62
+ end
63
+
64
+ if e = OpenMeta.setUserTags(new_tags, path:path)
59
65
  raise Openmeta::ObjCError, e.inspect
60
66
  end
67
+
68
+ OpenMetaPrefs.updatePrefsRecentTags(existing_tags, newTags:new_tags)
69
+ end
70
+
71
+ def add_tags(new_tags, to_files)
72
+ to_files = fu_list(to_files)
73
+
74
+ to_files.each { |file|
75
+ existing_tags = get_tags(file)
76
+
77
+ if e = OpenMeta.addUserTags(new_tags, path:file)
78
+ raise Openmeta::ObjCError, e.inspect
79
+ end
80
+
81
+ OpenMetaPrefs.updatePrefsRecentTags(existing_tags, newTags:new_tags)
82
+ }
83
+ end
84
+
85
+ def remove_tags(tags, from_files)
86
+ from_files = fu_list(from_files)
87
+
88
+ from_files.each { |file|
89
+ # duplicate a frozen array
90
+ existing_tags = get_tags(file).dup
91
+ unless existing_tags.empty?
92
+ existing_tags.delete_if { |t| tags.include?(t) }
93
+ set_tags(existing_tags, file)
94
+ end
95
+ }
61
96
  end
62
97
 
63
98
  def get_rating(path)
@@ -76,6 +111,7 @@ module Openmeta
76
111
  end
77
112
 
78
113
  def clone(from_file, to_files)
114
+
79
115
  unless File.exist?(from_file)
80
116
  raise Openmeta::PathError, "#{from_file} does not exist!"
81
117
  end
@@ -83,41 +119,30 @@ module Openmeta
83
119
  tags = get_tags(from_file)
84
120
  rating = get_rating(from_file)
85
121
 
86
- files.each { |file|
122
+ to_files = fu_list(to_files)
123
+ to_files.each { |file|
87
124
  set_tags(tags, file) unless tags.empty?
88
125
  set_rating(rating, file) unless rating == 0.0
89
126
  }
90
127
  end
91
128
 
92
129
  def clear(files)
130
+ files = fu_list(files)
93
131
  files.each { |file|
94
132
  set_tags([], file)
95
133
  set_rating(0.0, file)
96
134
  }
97
135
  end
98
136
 
99
- def add_tags(tags, to_files)
100
- to_files.each { |file|
101
- t = tags
102
- existing_tags = get_tags(file)
103
- # union
104
- t |= existing_tags if existing_tags
105
137
 
106
- unless t.eql? existing_tags
107
- set_tags(t, file)
108
- end
109
- }
138
+ def recent_tags
139
+ OpenMetaPrefs.recentTags
110
140
  end
111
141
 
112
- def remove_tags(tags, to_files)
113
- to_files.each { |file|
114
- # duplicate a frozen array
115
- existing_tags = get_tags(file).dup
116
- unless existing_tags.empty?
117
- existing_tags.delete_if { |t| tags.include?(t) }
118
- set_tags(existing_tags, file)
119
- end
120
- }
142
+ private
143
+
144
+ def fu_list(arg) #:nodoc:
145
+ [arg].flatten.map {|path| File.path(path) }
121
146
  end
122
147
 
123
148
  end
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+
3
+ describe "Openmeta" do
4
+ before :all do
5
+ Dir.chdir("test/")
6
+ end
7
+
8
+ context "with new files" do
9
+ before :all do
10
+ @testfiles = ['testfile1.openmeta', 'testfile2.openmeta']
11
+ FileUtils .touch @testfiles
12
+ end
13
+
14
+ it "should return raise ArgumentError if file does not exist" do
15
+ expect { Openmeta.get_tags("/path/to/nowhere") }.to raise_error(Openmeta::ObjCError)
16
+ end
17
+
18
+ it "should set tags and rating correctly" do
19
+ tags = ["Test","Tag"]
20
+ rating = 4
21
+ Openmeta.set_tags(tags, @testfiles[0])
22
+ Openmeta.set_rating(rating, @testfiles[0])
23
+
24
+ rtags = Openmeta.get_tags(@testfiles[0])
25
+ rrating = Openmeta.get_rating(@testfiles[0])
26
+ rtags.should == tags
27
+ rrating.should == rating
28
+ end
29
+
30
+ it "should clone tags and ratings correctly" do
31
+ tags = ["Test","Tag"]
32
+ rating = 4
33
+ Openmeta.clone(@testfiles[0], @testfiles[1])
34
+
35
+ rtags = Openmeta.get_tags(@testfiles[1])
36
+ rrating = Openmeta.get_rating(@testfiles[1])
37
+ rtags.should == tags
38
+ rrating.should == rating
39
+ end
40
+
41
+ it "should add tags correctly" do
42
+ tags = ["Test","Tag"] << 'Favorite'
43
+ Openmeta.add_tags(['Favorite'], @testfiles[1])
44
+
45
+ rtags = Openmeta.get_tags(@testfiles[1])
46
+ rtags.should match_array(tags)
47
+ end
48
+
49
+ it "should remove tags correctly" do
50
+ tags = ["Test", "Favorite"]
51
+ Openmeta.remove_tags(['Tag'], @testfiles[1])
52
+
53
+ rtags = Openmeta.get_tags(@testfiles[1])
54
+ rtags.should match_array(tags)
55
+ end
56
+
57
+ after :all do
58
+ FileUtils.safe_unlink(@testfiles)
59
+ end
60
+
61
+ context "recent tags" do
62
+ it "should contains recently used tags" do
63
+ Openmeta.recent_tags.should include("Test", "Tag", "Favorite")
64
+ end
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,26 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require "rspec"
4
+
5
+ require "openmeta"
6
+ require 'fileutils'
7
+
8
+ RSpec.configure do |c|
9
+ c.color_enabled = true
10
+
11
+ # Use color not only in STDOUT but also in pagers and files
12
+ c.tty = true
13
+
14
+ c.formatter = :documentation # :progress, :html, :textmate
15
+
16
+ c.mock_with :rspec
17
+ end
18
+
19
+ class String
20
+ def strip_heredoc
21
+ indent = scan(/^[ \t]*(?=\S)/).min.size || 0
22
+ gsub(/^[ \t]{#{indent}}/, '')
23
+ end
24
+ end
25
+
26
+
metadata CHANGED
@@ -1,60 +1,210 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: openmeta.rb
3
- version: !ruby/object:Gem::Version
4
- version: 1.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Zhao Cai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2013-03-31 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2013-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: thor
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
19
17
  - - ~>
20
- - !ruby/object:Gem::Version
18
+ - !ruby/object:Gem::Version
21
19
  version: 0.17.0
22
20
  type: :runtime
23
- version_requirements: *id001
24
- - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.17.0
27
+ - !ruby/object:Gem::Dependency
25
28
  name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.10'
34
+ type: :development
26
35
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
29
38
  - - ~>
30
- - !ruby/object:Gem::Version
31
- version: "3.10"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '2.13'
32
48
  type: :development
33
- version_requirements: *id002
34
- - !ruby/object:Gem::Dependency
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '2.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 10.0.0
69
+ - !ruby/object:Gem::Dependency
35
70
  name: hoe
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
36
77
  prerelease: false
37
- requirement: &id003 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- version: "3.5"
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hoe-gemspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hoe-git
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
42
104
  type: :development
43
- version_requirements: *id003
44
- description: openMeta in Ruby (MacRuby, more exactly!). This gem ports [openmeta]( http://code.google.com/p/openmeta/ ) api to macruby using framework.
45
- email:
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hoe-version
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: hoe-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: terminal-notifier-guard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: growl
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description: openMeta in Ruby (MacRuby, more exactly!). This gem ports [openmeta](
196
+ http://code.google.com/p/openmeta/ ) api to macruby using framework.
197
+ email:
46
198
  - caizhaoff@gmail.com
47
- executables:
199
+ executables:
48
200
  - tag
49
201
  extensions: []
50
-
51
- extra_rdoc_files:
202
+ extra_rdoc_files:
52
203
  - History.txt
53
204
  - Manifest.txt
54
- files:
205
+ files:
55
206
  - .ruby-version
56
- - Gemfile
57
- - Gemfile.lock
207
+ - Guardfile
58
208
  - History.txt
59
209
  - Manifest.txt
60
210
  - README.md
@@ -72,32 +222,33 @@ files:
72
222
  - lib/openmeta/friendly_errors.rb
73
223
  - lib/openmeta/ui.rb
74
224
  - lib/openmeta/version.rb
225
+ - spec/openmeta_spec.rb
226
+ - spec/spec_helper.rb
227
+ - .gemtest
75
228
  homepage: http://zhaocai.github.com/openmeta.rb
76
- licenses: []
77
-
229
+ licenses:
230
+ - GPL-3
78
231
  metadata: {}
79
-
80
232
  post_install_message:
81
- rdoc_options:
233
+ rdoc_options:
82
234
  - --main
83
235
  - README.md
84
- require_paths:
236
+ require_paths:
85
237
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
87
- requirements:
88
- - &id004
89
- - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
92
- required_rubygems_version: !ruby/object:Gem::Requirement
93
- requirements:
94
- - *id004
238
+ required_ruby_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ! '>='
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ required_rubygems_version: !ruby/object:Gem::Requirement
244
+ requirements:
245
+ - - ! '>='
246
+ - !ruby/object:Gem::Version
247
+ version: '0'
95
248
  requirements: []
96
-
97
249
  rubyforge_project: openmeta.rb
98
250
  rubygems_version: 2.0.3
99
251
  signing_key:
100
252
  specification_version: 4
101
253
  summary: openMeta in Ruby (MacRuby, more exactly!)
102
254
  test_files: []
103
-
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
-
5
- source "https://rubygems.org/"
6
-
7
- gem "thor", "~>0.17.0"
8
-
9
- gem "rdoc", "~>3.10", :group => [:development, :test]
10
- gem "hoe", "~>3.5", :group => [:development, :test]
11
-
12
- # vim: syntax=ruby
data/Gemfile.lock DELETED
@@ -1,13 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- hoe (3.5.2)
5
- rake (>= 0.8, < 11.0)
6
-
7
- PLATFORMS
8
- ruby
9
-
10
- DEPENDENCIES
11
- hoe (~> 3.5)
12
- rdoc (~> 3.10)
13
- thor (~> 0.17.0)