sugarcube 1.6.3 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e76184529e38be1dcbbc47be49bcf043f57dec8
4
- data.tar.gz: 600450d1cb5c231211eb6d2c212e7129d1f796fb
3
+ metadata.gz: 71dba0b8f4d8314be94992fa8750a69078369e58
4
+ data.tar.gz: 6a7bd82342aa34bcf53f9c92d379e8f482242af5
5
5
  SHA512:
6
- metadata.gz: 44e2d8c95356fcc30bc5f34025144d8fe3354d6dc997065e2bc2c101873ad81140b4db92bd38dc67ae4b3a252023223ebfbe7ad055cc61ed46bbbc45333ce398
7
- data.tar.gz: 58c854296a658b07d0092a844b150224da33777c192e9313e8ea0e778e2237d103b0d38ae977e5157adb81561cfe19f84a121039142e687c3826d340b3579ca9
6
+ metadata.gz: 57c109540763823be9f371367cc126f7f1b5e19e28a386a9378b7bb07b20a2d2051a3a06cf90580728e74af904d5170403a21489d1a076455cd52ada3caa5d37
7
+ data.tar.gz: e7b8ee3c5acbef141edfda5647b464d38d6d75f10fae2d3422db77a753505f6a6df846b5ab5f52618b872da24427ce0d70988b45b0c6b82f29655d15b2efbf4c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sugarcube (1.6.3)
4
+ sugarcube (1.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1200,8 +1200,8 @@ some problems with on RubyMotion (it worked, but not *always*. Very strange).
1200
1200
  Files
1201
1201
  -----
1202
1202
 
1203
- Methods to find document files, resource files, cache files, temporary files, and to access
1204
- entries out of the Info.plist file.
1203
+ Methods to find document files, resource files, cache files, temporary files, access
1204
+ entries out of the Info.plist file, and write data/arrays/dictionaries to a file.
1205
1205
 
1206
1206
  > `require 'sugarcube-files'`
1207
1207
 
@@ -1226,6 +1226,19 @@ entries out of the Info.plist file.
1226
1226
 
1227
1227
  # access data from Info.plist
1228
1228
  "CFBundleVersion".info_plist # => NSBundle.mainBundle.infoDictionary["CFBundleVersion"]
1229
+
1230
+ # write to file
1231
+ [].write_to('array.plist'.document_path)
1232
+ array = NSArray.read_from('array.plist'.resource_path)
1233
+
1234
+ {}.write_to('dict.plist'.document_path)
1235
+ dict = NSDictionary.read_from('dict.plist'.resource_path)
1236
+
1237
+ data = UIImagePNGRepresentation('some_image'.uiimage)
1238
+ # using sugarcube-nsdata:
1239
+ # data = 'some_image'.uiimage.nsdata
1240
+ data.write_to('some_image.png'.document_path)
1241
+ image_data = NSData.read_from('some_image.png'.document_path)
1229
1242
  ```
1230
1243
 
1231
1244
  Localized
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '1.6.3'
2
+ Version = '1.7.0'
3
3
  end
@@ -0,0 +1,29 @@
1
+ class NSArray
2
+
3
+ class << self
4
+
5
+ def read_from(path_or_url)
6
+ case path_or_url
7
+ when NSURL
8
+ self.arrayWithContentsOfURL(path_or_url)
9
+ when NSString
10
+ self.arrayWithContentsOfFile(path_or_url)
11
+ else
12
+ false
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ def write_to(path_or_url, atomically=true)
19
+ case path_or_url
20
+ when NSURL
21
+ self.writeToURL(path_or_url, atomically: atomically)
22
+ when NSString
23
+ self.writeToFile(path_or_url, atomically: atomically)
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ class NSData
2
+
3
+ class << self
4
+
5
+ def read_from(path_or_url)
6
+ case path_or_url
7
+ when NSURL
8
+ self.dataWithContentsOfURL(path_or_url)
9
+ when NSString
10
+ self.dataWithContentsOfFile(path_or_url)
11
+ else
12
+ false
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ def write_to(path_or_url, atomically=true)
19
+ case path_or_url
20
+ when NSURL
21
+ self.writeToURL(path_or_url, atomically: atomically)
22
+ when NSString
23
+ self.writeToFile(path_or_url, atomically: atomically)
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ class NSDictionary
2
+
3
+ class << self
4
+
5
+ def read_from(path_or_url)
6
+ case path_or_url
7
+ when NSURL
8
+ self.dictionaryWithContentsOfURL(path_or_url)
9
+ when NSString
10
+ self.dictionaryWithContentsOfFile(path_or_url)
11
+ else
12
+ false
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ def write_to(path_or_url, atomically=true)
19
+ case path_or_url
20
+ when NSURL
21
+ self.writeToURL(path_or_url, atomically: atomically)
22
+ when NSString
23
+ self.writeToFile(path_or_url, atomically: atomically)
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ end
@@ -4,7 +4,7 @@ class NSData
4
4
  # @return [NSString]
5
5
  def nsstring(encoding=nil)
6
6
  if encoding
7
- return NSString.stringWithCString(self.bytes, encoding:encoding)
7
+ return NSString.stringWithCString(self.bytes, encoding: encoding)
8
8
  else
9
9
 
10
10
  return NSString.stringWithUTF8String(self)
@@ -14,7 +14,7 @@ class NSData
14
14
  # @return [UIImage]
15
15
  def uiimage(scale=nil)
16
16
  if scale
17
- return UIImage.imageWithData(self, scale:scale)
17
+ return UIImage.imageWithData(self, scale: scale)
18
18
  else
19
19
  return UIImage.imageWithData(self)
20
20
  end
@@ -23,9 +23,9 @@ class NSData
23
23
  def write_to(path_or_url, atomically=true)
24
24
  case path_or_url
25
25
  when NSURL
26
- self.writeToURL(path_or_url, atomically:atomically)
26
+ self.writeToURL(path_or_url, atomically: atomically)
27
27
  when NSString
28
- self.writeToFile(path_or_url, atomically:atomically)
28
+ self.writeToFile(path_or_url, atomically: atomically)
29
29
  else
30
30
  false
31
31
  end
@@ -0,0 +1,69 @@
1
+ describe 'NSArray' do
2
+
3
+ before do
4
+ @file_name = 'write_to_file.plist'.temporary_path
5
+ @url = NSURL.alloc.initFileURLWithPath 'write_to_file'.temporary_path
6
+ end
7
+
8
+ describe 'writing to a file' do
9
+ it 'should write [] to a file' do
10
+ subject = []
11
+ subject.write_to(@file_name).should == true
12
+ @file_name.file_exists?.should == true
13
+ end
14
+
15
+ it 'should write [] to a url' do
16
+ subject = []
17
+ subject.write_to(@url).should == true
18
+ @file_name.file_exists?.should == true
19
+ end
20
+
21
+ it 'should write [...] to a file' do
22
+ subject = [1,2,3]
23
+ subject.write_to(@file_name).should == true
24
+ @file_name.file_exists?.should == true
25
+ end
26
+
27
+ it 'should write [...] with nested objects to a file' do
28
+ subject = [1,2,[3,true,false,"",{}]]
29
+ subject.write_to(@file_name).should == true
30
+ @file_name.file_exists?.should == true
31
+ end
32
+ end
33
+
34
+ describe 'reading from a file' do
35
+
36
+ it 'should read [] from a file' do
37
+ subject = []
38
+ subject.write_to(@file_name).should == true
39
+ contents = NSArray.read_from(@file_name)
40
+ contents.should == subject
41
+ end
42
+
43
+ it 'should read [...] from a file' do
44
+ subject = [1,2,3]
45
+ subject.write_to(@file_name).should == true
46
+ contents = NSArray.read_from(@file_name)
47
+ contents.should == subject
48
+ end
49
+
50
+ it 'should read [...] with nested objects from a file' do
51
+ subject = [1,2,[3,true,false,"",{}]]
52
+ subject.write_to(@file_name).should == true
53
+ contents = NSArray.read_from(@file_name)
54
+ contents.should == subject
55
+ end
56
+
57
+ it 'should not have a file called "wtf is this"' do
58
+ 'wtf is this'.document_path.file_exists?.should == false
59
+ end
60
+
61
+ it 'should return nil for files that don\'t exist' do
62
+ file_name = 'wtf is this'.document_path
63
+ contents = NSArray.read_from(file_name)
64
+ contents.should == nil
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,45 @@
1
+ describe 'NSData' do
2
+
3
+ before do
4
+ @file_name = 'write_to_file'.temporary_path
5
+ @url = NSURL.alloc.initFileURLWithPath 'write_to_file'.temporary_path
6
+ end
7
+
8
+ describe 'writing to a file' do
9
+ it 'should write data to a file' do
10
+ subject = 'data'.dataUsingEncoding(NSUTF8StringEncoding)
11
+ subject.write_to(@file_name).should == true
12
+ @file_name.file_exists?.should == true
13
+ end
14
+ end
15
+
16
+ describe 'writing to a url' do
17
+ it 'should write data to a url' do
18
+ subject = 'data'.dataUsingEncoding(NSUTF8StringEncoding)
19
+ subject.write_to(@url).should == true
20
+ @file_name.file_exists?.should == true
21
+ end
22
+ end
23
+
24
+ describe 'reading from a file' do
25
+
26
+ it 'should read data from a file' do
27
+ subject = 'data'.dataUsingEncoding(NSUTF8StringEncoding)
28
+ subject.write_to(@file_name).should == true
29
+ contents = NSData.read_from(@file_name)
30
+ contents.should == subject
31
+ end
32
+
33
+ it 'should not have a file called "wtf is this"' do
34
+ 'wtf is this'.document_path.file_exists?.should == false
35
+ end
36
+
37
+ it 'should return nil for files that don\'t exist' do
38
+ file_name = 'wtf is this'.document_path
39
+ contents = NSData.read_from(file_name)
40
+ contents.should == nil
41
+ end
42
+
43
+ end
44
+
45
+ end
data/spec/nsdata_spec.rb CHANGED
@@ -55,29 +55,4 @@ describe "NSData" do
55
55
 
56
56
  end
57
57
 
58
- describe "write_to" do
59
-
60
- after do
61
- "a-z".document.remove!
62
- end
63
-
64
- it "should write data to spcified path" do
65
- path = "a-z".document
66
- contents = (:a..:z).to_a.join
67
- contents.nsdata.write_to(path).should == true
68
- path.exists?.should == true
69
- path.fileurl.nsdata.nsstring.should == contents
70
- end
71
-
72
- it "should write data to spcified url" do
73
- url = NSURL.alloc.initFileURLWithPath "a-z".document
74
- contents = (:a..:z).to_a.join
75
- contents.nsdata.write_to(url).should == true
76
- path = "a-z".document
77
- path.exists?.should == true
78
- url.nsdata.nsstring.should == contents
79
- end
80
-
81
- end
82
-
83
58
  end
@@ -0,0 +1,77 @@
1
+ describe 'NSDictionary' do
2
+
3
+ before do
4
+ @file_name = 'write_to_file.plist'.temporary_path
5
+ @url = NSURL.alloc.initFileURLWithPath 'write_to_file.plist'.temporary_path
6
+ end
7
+
8
+ describe 'writing to a file' do
9
+ it 'should write {} to a file' do
10
+ subject = {}
11
+ subject.write_to(@file_name).should == true
12
+ @file_name.file_exists?.should == true
13
+ end
14
+
15
+ it 'should write {...} to a url' do
16
+ subject = { 'a' => 1, 'b' => 2, 'c' => 3 }
17
+ subject.write_to(@url).should == true
18
+ @file_name.file_exists?.should == true
19
+ end
20
+
21
+ it 'should write {...} with nested objects to a file' do
22
+ subject = { 'a' => 1, 'b' => 2, 'c' => { 'd' => 3, 'true' => true, 'false' => false, 'empty_string' => "", 'empty_dictionary' => {}}}
23
+ subject.write_to(@file_name).should == true
24
+ @file_name.file_exists?.should == true
25
+ end
26
+
27
+ it 'should write {...} with symbols to a file' do
28
+ subject = { a: 1, b: 2, c: 3 }
29
+ subject.write_to(@file_name).should == true
30
+ @file_name.file_exists?.should == true
31
+ end
32
+ end
33
+
34
+ describe 'reading from a file' do
35
+
36
+ it 'should read {} from a file' do
37
+ subject = {}
38
+ subject.write_to(@file_name).should == true
39
+ contents = NSDictionary.read_from(@file_name)
40
+ contents.should == subject
41
+ end
42
+
43
+ it 'should read {...} from a file' do
44
+ subject = { 'a' => 1, 'b' => 2, 'c' => 3 }
45
+ subject.write_to(@file_name).should == true
46
+ contents = NSDictionary.read_from(@file_name)
47
+ contents.should == subject
48
+ end
49
+
50
+ it 'should read {...} with nested objects from a file' do
51
+ subject = { 'a' => 1, 'b' => 2, 'c' => { 'd' => 3, 'true' => true, 'false' => false, 'empty_string' => "", 'empty_dictionary' => {}}}
52
+ subject.write_to(@file_name).should == true
53
+ contents = NSDictionary.read_from(@file_name)
54
+ contents.should == subject
55
+ end
56
+
57
+ it 'should read {...} with symbols from a file' do
58
+ subject = { a: 1, b: 2, c: 3 }
59
+ read_contents = { 'a' => 1, 'b' => 2, 'c' => 3 }
60
+ subject.write_to(@file_name).should == true
61
+ contents = NSDictionary.read_from(@file_name)
62
+ contents.should == read_contents
63
+ end
64
+
65
+ it 'should not have a file called "wtf is this"' do
66
+ 'wtf is this'.document_path.file_exists?.should == false
67
+ end
68
+
69
+ it 'should return nil for files that don\'t exist' do
70
+ file_name = 'wtf is this'.document_path
71
+ contents = NSDictionary.read_from(file_name)
72
+ contents.should == nil
73
+ end
74
+
75
+ end
76
+
77
+ end
data/spec/uiview_spec.rb CHANGED
@@ -12,7 +12,7 @@ describe "UIView" do
12
12
  image.class.should == UIImage
13
13
  CGSizeEqualToSize(image.size, [10, 10]).should == true
14
14
  image.scale.should == UIScreen.mainScreen.scale
15
- # file = 'uiview_uiimage_test.png'.document
15
+ # file = 'uiview_uiimage_test.png'.document_path
16
16
  # image.nsdata.write_to(file)
17
17
  end
18
18
 
@@ -31,25 +31,25 @@ describe "UIView" do
31
31
  red = UIView.alloc.initWithFrame([[0, 0], [8, 8]])
32
32
  red.backgroundColor = :red.uicolor(0.5)
33
33
  test << red
34
- # file = 'uiview_uiimage_red.png'.document
34
+ # file = 'uiview_uiimage_red.png'.document_path
35
35
  # red.uiimage.nsdata.write_to(file)
36
36
 
37
37
  green = UIView.alloc.initWithFrame([[10, 0], [10, 10]])
38
38
  green.backgroundColor = :green.uicolor(0.5)
39
39
  test << green
40
- # file = 'uiview_uiimage_green.png'.document
40
+ # file = 'uiview_uiimage_green.png'.document_path
41
41
  # green.uiimage.nsdata.write_to(file)
42
42
 
43
43
  blue = UIView.alloc.initWithFrame([[0, 10], [10, 10]])
44
44
  blue.backgroundColor = :blue.uicolor(0.5)
45
45
  test << blue
46
- # file = 'uiview_uiimage_blue.png'.document
46
+ # file = 'uiview_uiimage_blue.png'.document_path
47
47
  # blue.uiimage.nsdata.write_to(file)
48
48
 
49
49
  white = UIView.alloc.initWithFrame([[10, 10], [10, 10]])
50
50
  white.backgroundColor = :white.uicolor(0.5)
51
51
  test << white
52
- # file = 'uiview_uiimage_white.png'.document
52
+ # file = 'uiview_uiimage_white.png'.document_path
53
53
  # white.uiimage.nsdata.write_to(file)
54
54
 
55
55
  gray = UIView.alloc.initWithFrame([[18, 18], [2, 2]])
@@ -60,7 +60,7 @@ describe "UIView" do
60
60
  image.class.should == UIImage
61
61
  CGSizeEqualToSize(image.size, [10, 10]).should == true
62
62
  image.scale.should == UIScreen.mainScreen.scale
63
- # file = 'uiview_uiimage_small.png'.document
63
+ # file = 'uiview_uiimage_small.png'.document_path
64
64
  # image.nsdata.write_to(file)
65
65
 
66
66
  image = test.uiimage(:all)
@@ -72,7 +72,7 @@ describe "UIView" do
72
72
  image.class.should == UIImage
73
73
  CGSizeEqualToSize(image.size, [20, 20]).should == true
74
74
  image.scale.should == UIScreen.mainScreen.scale
75
- # file = 'uiview_uiimage_big.png'.document
75
+ # file = 'uiview_uiimage_big.png'.document_path
76
76
  # image.nsdata.write_to(file)
77
77
  end
78
78
 
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.6.3
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-06-06 00:00:00.000000000 Z
14
+ date: 2014-07-03 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: |
17
17
  == Description
@@ -88,6 +88,9 @@ files:
88
88
  - lib/sugarcube-factories/uitableview.rb
89
89
  - lib/sugarcube-factories/uitableviewcell.rb
90
90
  - lib/sugarcube-files.rb
91
+ - lib/sugarcube-files/nsarray.rb
92
+ - lib/sugarcube-files/nsdata.rb
93
+ - lib/sugarcube-files/nsdictionary.rb
91
94
  - lib/sugarcube-files/nsstring.rb
92
95
  - lib/sugarcube-files/nsstring_deprecated.rb
93
96
  - lib/sugarcube-foundation.rb
@@ -213,13 +216,16 @@ files:
213
216
  - spec/image_scale_spec.rb
214
217
  - spec/image_uiimage_filters_spec.rb
215
218
  - spec/notification_spec.rb
219
+ - spec/nsarray_files_spec.rb
216
220
  - spec/nsarray_spec.rb
217
221
  - spec/nsattributedstring_spec.rb
218
222
  - spec/nscoder_spec.rb
223
+ - spec/nsdata_files_spec.rb
219
224
  - spec/nsdata_spec.rb
220
225
  - spec/nsdate_delta_spec.rb
221
226
  - spec/nsdate_spec.rb
222
227
  - spec/nsdate_upto_spec.rb
228
+ - spec/nsdictionary_files_spec.rb
223
229
  - spec/nsorderedset_spec.rb
224
230
  - spec/nsset_spec.rb
225
231
  - spec/nsstring_files_spec.rb
@@ -293,13 +299,16 @@ test_files:
293
299
  - spec/image_scale_spec.rb
294
300
  - spec/image_uiimage_filters_spec.rb
295
301
  - spec/notification_spec.rb
302
+ - spec/nsarray_files_spec.rb
296
303
  - spec/nsarray_spec.rb
297
304
  - spec/nsattributedstring_spec.rb
298
305
  - spec/nscoder_spec.rb
306
+ - spec/nsdata_files_spec.rb
299
307
  - spec/nsdata_spec.rb
300
308
  - spec/nsdate_delta_spec.rb
301
309
  - spec/nsdate_spec.rb
302
310
  - spec/nsdate_upto_spec.rb
311
+ - spec/nsdictionary_files_spec.rb
303
312
  - spec/nsorderedset_spec.rb
304
313
  - spec/nsset_spec.rb
305
314
  - spec/nsstring_files_spec.rb