sugarcube 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sugarcube (1.3.11)
4
+ sugarcube (1.4.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1077,21 +1077,28 @@ some problems with on RubyMotion (it worked, but not *always*. Very strange).
1077
1077
  Files
1078
1078
  -----
1079
1079
 
1080
- Methods to find document files, resource files, cache files, and to access
1080
+ Methods to find document files, resource files, cache files, temporary files, and to access
1081
1081
  entries out of the Info.plist file.
1082
1082
 
1083
1083
  > `require 'sugarcube-files'`
1084
1084
 
1085
1085
  ```ruby
1086
1086
  # file operations
1087
- "my.plist".exists? # => NSFileManager.defaultManager.fileExistsAtPath("my.plist")
1088
- "my.plist".document # => NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0].stringByAppendingPathComponent("my.plist")
1089
- "my.plist".cache # => NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true)[0].stringByAppendingPathComponent("my.plist")
1090
- "my.plist".remove! # => NSFileManager.defaultManager.removeItemAtPath("my.plist".document, error: error) (returns error, if any occurred)
1087
+ "my.plist".file_exists? # => NSFileManager.defaultManager.fileExistsAtPath("my.plist")
1088
+
1089
+ "my.plist".remove_file! # => NSFileManager.defaultManager.removeItemAtPath("my.plist".document, error: error) (returns error, if any occurred)
1090
+
1091
+ "my.plist".document_path # => NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0].stringByAppendingPathComponent("my.plist")
1092
+ "my.plist".cache_path # => NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true)[0].stringByAppendingPathComponent("my.plist")
1093
+ "my.plist".temporary_path # => NSTemporaryDirectory().stringByAppendingPathComponent("my.plist")
1094
+
1095
+ # all of these can be turned into a URL, too
1096
+ "my.plist".temporary_path.file_url # => NSURL.fileURLWithPath("my.plist".temporary_path)
1091
1097
 
1092
1098
  # get the resource path, useful if you include json files or images you manipulate in the app
1093
- "my.plist".resource # => NSBundle.mainBundle.resourcePath.stringByAppendingPathComponent("my.plist")
1094
- # same, but get a URL instead - often used to display a static HTML page that is stored in resources
1099
+ "my.plist".resource_path # => NSBundle.mainBundle.resourcePath.stringByAppendingPathComponent("my.plist")
1100
+ # same, but get a URL instead - often used to display a static HTML page that is stored in resources.
1101
+ # getting a path URL from a resource is just a little different from creating a URL from any other type of path
1095
1102
  "index.html".resource_url # => NSBundle.mainBundle.URLForResource("index", withExtension:"html")
1096
1103
 
1097
1104
  # access data from Info.plist
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '1.4.1'
2
+ Version = '1.4.2'
3
3
  end
@@ -1,39 +1,46 @@
1
1
  class NSString
2
2
 
3
- def document
3
+ def document_path
4
4
  @@sugarcube_docs ||= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
5
5
  return self if self.hasPrefix(@@sugarcube_docs)
6
6
 
7
7
  @@sugarcube_docs.stringByAppendingPathComponent(self)
8
8
  end
9
-
10
- def cache
9
+
10
+ def cache_path
11
11
  @@sugarcube_caches ||= NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true)[0]
12
12
  return self if self.hasPrefix(@@sugarcube_caches)
13
13
 
14
14
  @@sugarcube_caches.stringByAppendingPathComponent(self)
15
15
  end
16
16
 
17
- def app_support
17
+ def app_support_path
18
18
  @@sugarcube_app_suppert ||= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true)[0]
19
19
  return self if self.hasPrefix(@@sugarcube_app_suppert)
20
20
 
21
21
  @@sugarcube_app_suppert.stringByAppendingPathComponent(self)
22
22
  end
23
23
 
24
- def exists?
24
+ def temporary_path
25
+ @@sugarcube_temporary ||= NSTemporaryDirectory()
26
+ return self if self.hasPrefix(@@sugarcube_temporary)
27
+
28
+ @@sugarcube_temporary.stringByAppendingPathComponent(self)
29
+ end
30
+
31
+ def file_exists?
25
32
  path = self.hasPrefix('/') ? self : self.document
26
33
  NSFileManager.defaultManager.fileExistsAtPath(path)
27
34
  end
28
35
 
29
- def remove!
36
+ def remove_file!
30
37
  ptr = Pointer.new(:id)
31
38
  path = self.hasPrefix('/') ? self : self.document
32
39
  NSFileManager.defaultManager.removeItemAtPath(path, error:ptr)
33
40
  ptr[0]
34
41
  end
35
42
 
36
- def resource
43
+ def resource_path
37
44
  @@sugarcube_resources ||= NSBundle.mainBundle.resourcePath
38
45
  return self if self.hasPrefix(@@sugarcube_resources)
39
46
 
@@ -41,15 +48,19 @@ class NSString
41
48
  end
42
49
 
43
50
  def resource_exists?
44
- NSFileManager.defaultManager.fileExistsAtPath(self.resource)
51
+ self.resource_path.file_exists?
45
52
  end
46
53
 
47
54
  def resource_url
48
- a = self.split(".")
55
+ a = self.split('.')
49
56
  ext = a.pop if a.size >= 2
50
57
  NSBundle.mainBundle.URLForResource(a.join("."), withExtension:ext)
51
58
  end
52
59
 
60
+ def file_url
61
+ NSURL.fileURLWithPath(self)
62
+ end
63
+
53
64
  # It's convenient to store a property which is dependent on an environment to
54
65
  # Info.plist. For instance, to use a different server between development and
55
66
  # release versions.
@@ -69,7 +80,7 @@ class NSString
69
80
  # 'VerifyURL'.info_plist
70
81
  # </code>
71
82
  def info_plist
72
- NSBundle.mainBundle.infoDictionary.valueForKey self
83
+ NSBundle.mainBundle.infoDictionary.valueForKey self
73
84
  end
74
85
 
75
86
  end
@@ -0,0 +1,45 @@
1
+ class NSString
2
+
3
+ # This method will be removed in iOS 9
4
+ def document
5
+ NSLog('Warning: SugarCube\'s String#document method has been deprecated in favor of String#document_path')
6
+ self.document_path
7
+ end
8
+
9
+ # This method will be removed in iOS 9
10
+ def cache
11
+ NSLog('Warning: SugarCube\'s String#cache method has been deprecated in favor of String#cache_path')
12
+ self.cache_path
13
+ end
14
+
15
+ # This method will be removed in iOS 9
16
+ def app_support
17
+ NSLog('Warning: SugarCube\'s String#app_support method has been deprecated in favor of String#app_support_path')
18
+ self.app_support_path
19
+ end
20
+
21
+ # This method will be removed in iOS 9
22
+ def temporary
23
+ NSLog('Warning: SugarCube\'s String#temporary method has been deprecated in favor of String#temporary_path')
24
+ self.temporary_path
25
+ end
26
+
27
+ # This method will be removed in iOS 9
28
+ def exists?
29
+ NSLog('Warning: SugarCube\'s String#exists? method has been deprecated in favor of String#file_exists?')
30
+ self.file_exists?
31
+ end
32
+
33
+ # This method will be removed in iOS 9
34
+ def remove!
35
+ NSLog('Warning: SugarCube\'s String#remove! method has been deprecated in favor of String#remove_file!')
36
+ self.remove_file!
37
+ end
38
+
39
+ # This method will be removed in iOS 9
40
+ def resource
41
+ NSLog('Warning: SugarCube\'s String#resource method has been deprecated in favor of String#resource_path')
42
+ self.resource_path
43
+ end
44
+
45
+ end
@@ -35,5 +35,9 @@ class NSArray
35
35
  def nsset
36
36
  NSSet.setWithArray self
37
37
  end
38
+
39
+ def nsorderedset
40
+ NSOrderedSet.orderedSetWithArray self
41
+ end
38
42
 
39
43
  end
@@ -0,0 +1,7 @@
1
+ class NSOrderedSet
2
+
3
+ alias :to_a :array
4
+
5
+ end
6
+
7
+
@@ -27,7 +27,7 @@ describe "Base Methods" do
27
27
  describe "parses iso8601 dates" do
28
28
 
29
29
  it "parses '2013-08-22T21:34:48.874Z'" do
30
- t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874Z")
30
+ t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874Z").getutc
31
31
  t.month.should == 8
32
32
  t.day.should == 22
33
33
  t.year.should == 2013
@@ -37,7 +37,7 @@ describe "Base Methods" do
37
37
  end
38
38
 
39
39
  it "parses '2013-08-22T21:34:48.874'" do
40
- t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874")
40
+ t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874").getutc
41
41
  t.month.should == 8
42
42
  t.day.should == 22
43
43
  t.year.should == 2013
@@ -47,7 +47,7 @@ describe "Base Methods" do
47
47
  end
48
48
 
49
49
  it "parses '2013-08-22T21:34:48Z'" do
50
- t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48Z")
50
+ t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48Z").getutc
51
51
  t.month.should == 8
52
52
  t.day.should == 22
53
53
  t.year.should == 2013
@@ -56,7 +56,7 @@ describe "Base Methods" do
56
56
  end
57
57
 
58
58
  it "parses '2013-08-22T21:34:48'" do
59
- t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48")
59
+ t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48").getutc
60
60
  t.month.should == 8
61
61
  t.day.should == 22
62
62
  t.year.should == 2013
@@ -0,0 +1,13 @@
1
+ describe "NSOrderedSet" do
2
+
3
+ # NSOrderedSet keesp ordering
4
+ it "should have a method #to_a" do
5
+ [1,0].nsorderedset.to_a.should == [1,0]
6
+ end
7
+
8
+ # NSSet doesn't keep ordering. It's sorted.
9
+ it "should have a method #to_a" do
10
+ [1,0].nsset.to_a.should == [0,1]
11
+ end
12
+
13
+ end
@@ -1,30 +1,37 @@
1
1
  describe 'NSString' do
2
2
 
3
- it "should have a #document method" do
4
- 'foo'.document.hasPrefix('/Users').should == true
5
- 'foo'.document.hasSuffix('Documents/foo').should == true
3
+ it "should have a #document_path method" do
4
+ 'foo'.document_path.should.start_with?('/Users')
5
+ 'foo'.document_path.should.end_with?('Documents/foo')
6
6
  end
7
7
 
8
- it "should have a #cache method" do
9
- 'foo'.cache.hasPrefix('/Users').should == true
10
- 'foo'.cache.hasSuffix('Library/Caches/foo').should == true
8
+ it "should have a #cache_path method" do
9
+ 'foo'.cache_path.should.start_with?('/Users')
10
+ 'foo'.cache_path.should.end_with?('Library/Caches/foo')
11
11
  end
12
12
 
13
- it "should have a #app_support method" do
14
- 'foo'.app_support.hasPrefix('/Users').should == true
15
- 'foo'.app_support.hasSuffix('Library/Application Support/foo').should == true
13
+ it "should have a #app_support_path method" do
14
+ 'foo'.app_support_path.should.start_with?('/Users')
15
+ 'foo'.app_support_path.should.end_with?('Library/Application Support/foo')
16
16
  end
17
17
 
18
- it "should have an #exists? method" do
18
+ it "should have a #temporary_path method" do
19
+ 'foo'.temporary_path.should.start_with?('/Users')
20
+ 'foo'.temporary_path.should.end_with?('tmp/foo')
21
+ end
22
+
23
+ it "should have an #file_exists? method" do
24
+ 'foo'.document.file_exists?.should == false
19
25
  'foo'.document.exists?.should == false
20
26
  end
21
27
 
22
- it "should have a remove! method" do
23
- unless 'remove_me'.exists?
24
- NSData.data.writeToFile('remove_me'.document, atomically: true)
28
+ it "should have a remove_file! method" do
29
+ filename = 'remove_me'.document_path
30
+ unless filename.file_exists?
31
+ NSData.data.writeToFile(filename, atomically: true)
25
32
  end
26
- 'remove_me'.document.remove!
27
- 'remove_me'.exists?.should == false
33
+ filename.remove_file!
34
+ filename.file_exists?.should == false
28
35
  end
29
36
 
30
37
  it "should have a resource_exists? method" do
@@ -32,105 +39,105 @@ describe 'NSString' do
32
39
  'foo'.resource_exists?.should == false
33
40
  end
34
41
 
35
- describe "exists?" do
42
+ describe "file_exists?" do
36
43
 
37
- it "should not exists" do
38
- "abc".exists?.should == false
44
+ it "should not file_exists" do
45
+ "abc".file_exists?.should == false
39
46
  end
40
47
 
41
- it "should not exists" do
42
- "abc".cache.exists?.should == false
48
+ it "should not file_exists" do
49
+ "abc".cache.file_exists?.should == false
43
50
  end
44
51
 
45
- it "should not exists" do
46
- "abc".resource.exists?.should == false
52
+ it "should not file_exists" do
53
+ "abc".resource.file_exists?.should == false
47
54
  end
48
55
 
49
56
  describe "in document" do
50
57
  before do
51
- "abc".writeToFile "abc".document, atomically:true
58
+ "abc".writeToFile "abc".document_path, atomically:true
52
59
  end
53
60
  after do
54
- NSFileManager.defaultManager.removeItemAtPath "abc".document, error:nil
61
+ NSFileManager.defaultManager.removeItemAtPath "abc".document_path, error:nil
55
62
  end
56
63
 
57
- it "should be exists" do
58
- "abc".exists?.should == true
64
+ it "should be file_exists" do
65
+ "abc".file_exists?.should == true
59
66
  end
60
67
  end
61
68
 
62
69
  describe "in cache" do
63
70
  before do
64
- "abc".writeToFile "abc".cache, atomically:true
71
+ "abc".writeToFile "abc".cache_path, atomically:true
65
72
  end
66
73
  after do
67
- NSFileManager.defaultManager.removeItemAtPath "abc".cache, error:nil
74
+ NSFileManager.defaultManager.removeItemAtPath "abc".cache_path, error:nil
68
75
  end
69
76
 
70
- it "should be exists" do
71
- "abc".cache.exists?.should == true
77
+ it "should be file_exists" do
78
+ "abc".cache_path.file_exists?.should == true
72
79
  end
73
80
  end
74
81
 
75
82
  describe "in resource" do
76
- it "should be exists" do
77
- "info.plist".resource.exists?.should == true
83
+ it "should be file_exists" do
84
+ "info.plist".resource.file_exists?.should == true
78
85
  end
79
86
  end
80
87
 
81
88
  end
82
89
 
83
- describe "remove!" do
90
+ describe "remove_file!" do
84
91
 
85
92
  describe "in document" do
86
93
  before do
87
- "abc".writeToFile "abc".document, atomically:true
94
+ "abc".writeToFile "abc".document_path, atomically:true
88
95
  end
89
96
  after do
90
- NSFileManager.defaultManager.removeItemAtPath "abc".document, error:nil
97
+ NSFileManager.defaultManager.removeItemAtPath "abc".document_path, error:nil
91
98
  end
92
99
 
93
100
  it "should remove" do
94
- "abc".remove!.should == nil
95
- "abc".exists?.should == false
101
+ "abc".remove_file!.should == nil
102
+ "abc".file_exists?.should == false
96
103
  end
97
104
  end
98
105
 
99
106
  describe "in cache" do
100
107
  before do
101
- "abc".writeToFile "abc".cache, atomically:true
108
+ "abc".writeToFile "abc".cache_path, atomically:true
102
109
  end
103
110
  after do
104
- NSFileManager.defaultManager.removeItemAtPath "abc".cache, error:nil
111
+ NSFileManager.defaultManager.removeItemAtPath "abc".cache_path, error:nil
105
112
  end
106
113
 
107
114
  it "should remove" do
108
- path = "abc".cache
109
- path.remove!.should == nil
110
- path.exists?.should == false
115
+ path = "abc".cache_path
116
+ path.remove_file!.should == nil
117
+ path.file_exists?.should == false
111
118
  end
112
119
  end
113
120
 
114
121
  end
115
122
 
116
123
  describe 'resource()' do
117
- describe '"info.plist".resource' do
118
- before { @it = "info.plist".resource }
124
+ describe '"info.plist".resource_path' do
125
+ before { @it = "info.plist".resource_path }
119
126
  it 'should start with "/Users"' do
120
- @it.hasPrefix("/Users").should == true
127
+ @it.should.start_with?("/Users")
121
128
  end
122
129
  it 'should end with "SugarCube_spec.app/info.plist"' do
123
- @it.hasSuffix("SugarCube_spec.app/info.plist").should == true
130
+ @it.should.end_with?("SugarCube_spec.app/info.plist")
124
131
  end
125
132
  end
126
133
 
127
- describe '"PkgInfo".resource' do
128
- before { @it = "PkgInfo".resource }
134
+ describe '"PkgInfo".resource_path' do
135
+ before { @it = "PkgInfo".resource_path }
129
136
  it 'should start with "/Users"' do
130
- @it.hasPrefix("/Users").should == true
137
+ @it.should.start_with?("/Users")
131
138
  end
132
139
  it 'should end with "SugarCube_spec.app/PkgInfo"' do
133
- @it.hasSuffix("SugarCube_spec.app/PkgInfo").should == true
140
+ @it.should.end_with?("SugarCube_spec.app/PkgInfo")
134
141
  end
135
142
  end
136
143
  end
@@ -154,12 +161,12 @@ describe 'NSString' do
154
161
  before { @it = "PkgInfo".resource_url.absoluteString }
155
162
  it 'should start with "file://localhost/Users"' do
156
163
  (
157
- @it.hasPrefix("file://localhost/Users") ||
158
- @it.hasPrefix("file:///Users")
164
+ @it.start_with?("file://localhost/Users") ||
165
+ @it.start_with?("file:///Users")
159
166
  ).should == true
160
167
  end
161
168
  it 'should end with "SugarCube_spec.app/PkgInfo"' do
162
- @it.hasSuffix("SugarCube_spec.app/PkgInfo").should == true
169
+ @it.should.end_with?("SugarCube_spec.app/PkgInfo")
163
170
  end
164
171
  end
165
172
  end
@@ -180,5 +187,17 @@ describe 'NSString' do
180
187
  end
181
188
  end
182
189
 
190
+ describe 'file_url' do
191
+
192
+ it 'should convert path String to NSURL' do
193
+ 'test'.resource_path.file_url.should.is_a?(NSURL)
194
+ end
195
+
196
+ it 'should be a file path' do
197
+ 'test'.resource_path.file_url.absoluteString.should.start_with?('file://')
198
+ end
199
+
200
+ end
201
+
183
202
  end
184
203
 
@@ -179,6 +179,7 @@ describe 'UIAlertView' do
179
179
  proper_wait 0.6
180
180
  alert.textFieldAtIndex(0).text = 'test text'
181
181
  alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
182
+ proper_wait 0.1
182
183
 
183
184
  @called.should == true
184
185
  @text.should == 'test text'
@@ -191,6 +192,7 @@ describe 'UIAlertView' do
191
192
  proper_wait 0.6
192
193
  alert.textFieldAtIndex(0).text = 'test text'
193
194
  alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
195
+ proper_wait 0.1
194
196
 
195
197
  @text.should == 'test text'
196
198
  end
@@ -203,6 +205,7 @@ describe 'UIAlertView' do
203
205
  alert.textFieldAtIndex(0).text = 'test text 1'
204
206
  alert.textFieldAtIndex(1).text = 'test text 2'
205
207
  alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
208
+ proper_wait 0.1
206
209
 
207
210
  @text.should == 'test text 1 + test text 2'
208
211
  end
@@ -216,6 +219,7 @@ describe 'UIAlertView' do
216
219
  alert.textFieldAtIndex(0).text = 'test text 1'
217
220
  alert.textFieldAtIndex(1).text = 'test text 2'
218
221
  alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
222
+ proper_wait 0.1
219
223
 
220
224
  @text.should == 'test text 1 + test text 2'
221
225
  @touched_index.should == alert.cancelButtonIndex
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-01-24 00:00:00.000000000 Z
15
+ date: 2014-01-28 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: ! '== Description
18
18
 
@@ -98,10 +98,12 @@ files:
98
98
  - lib/sugarcube-factories/uitableviewcell.rb
99
99
  - lib/sugarcube-files.rb
100
100
  - lib/sugarcube-files/nsstring.rb
101
+ - lib/sugarcube-files/nsstring_deprecated.rb
101
102
  - lib/sugarcube-foundation.rb
102
103
  - lib/sugarcube-foundation/nsarray.rb
103
104
  - lib/sugarcube-foundation/nsindexpath.rb
104
105
  - lib/sugarcube-foundation/nsindexset.rb
106
+ - lib/sugarcube-foundation/nsorderedset.rb
105
107
  - lib/sugarcube-foundation/nsset.rb
106
108
  - lib/sugarcube-foundation/nsstring.rb
107
109
  - lib/sugarcube-foundation/nsurl.rb
@@ -225,6 +227,7 @@ files:
225
227
  - spec/nsdate_delta_spec.rb
226
228
  - spec/nsdate_spec.rb
227
229
  - spec/nsdate_upto_spec.rb
230
+ - spec/nsorderedset_spec.rb
228
231
  - spec/nsset_spec.rb
229
232
  - spec/nsstring_files_spec.rb
230
233
  - spec/nsstring_spec.rb
@@ -273,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
276
  version: '0'
274
277
  requirements: []
275
278
  rubyforge_project:
276
- rubygems_version: 1.8.11
279
+ rubygems_version: 1.8.25
277
280
  signing_key:
278
281
  specification_version: 3
279
282
  summary: Extensions for Ruby to make Rubymotion development more enjoyable, and hopefully
@@ -302,6 +305,7 @@ test_files:
302
305
  - spec/nsdate_delta_spec.rb
303
306
  - spec/nsdate_spec.rb
304
307
  - spec/nsdate_upto_spec.rb
308
+ - spec/nsorderedset_spec.rb
305
309
  - spec/nsset_spec.rb
306
310
  - spec/nsstring_files_spec.rb
307
311
  - spec/nsstring_spec.rb