sugarcube 0.20.5 → 0.20.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,4 +20,15 @@ class NSData
20
20
  end
21
21
  end
22
22
 
23
+ def write_to(path_or_url, atomically=true)
24
+ case path_or_url
25
+ when NSURL
26
+ self.writeToURL(path_or_url, atomically:atomically)
27
+ when NSString
28
+ self.writeToFile(path_or_url, atomically:atomically)
29
+ else
30
+ false
31
+ end
32
+ end
33
+
23
34
  end
@@ -4,6 +4,11 @@ class NSString
4
4
  def nsurl
5
5
  @url ||= NSURL.alloc.initWithString(self)
6
6
  end
7
+
8
+ # @return [NSURL]
9
+ def fileurl
10
+ @fileurl ||= NSURL.fileURLWithPath(self)
11
+ end
7
12
 
8
13
  # @return [NSData] NSData representation encoded using UTF8, or a specified
9
14
  # encoding
@@ -21,7 +21,8 @@ class NSString
21
21
 
22
22
  def remove!
23
23
  ptr = Pointer.new(:id)
24
- NSFileManager.defaultManager.removeItemAtPath(self.document, error:ptr)
24
+ path = self.hasPrefix('/') ? self : self.document
25
+ NSFileManager.defaultManager.removeItemAtPath(path, error:ptr)
25
26
  ptr[0]
26
27
  end
27
28
 
@@ -351,10 +351,13 @@ class UIView
351
351
  end
352
352
 
353
353
  self.animate(options) {
354
- offset = CGPoint.new(0, self.superview.bounds.size.height * 1.5)
355
- offset = CGPointApplyAffineTransform(offset, self.transform)
356
- self.transform = CGAffineTransformConcat(self.transform, CGAffineTransformMakeRotation(-Math::PI/4))
357
- self.center = CGPointMake(self.center.x + offset.x, self.center.y + offset.y)
354
+ window = UIApplication.sharedApplication.keyWindow || UIApplication.sharedApplication.windows[0]
355
+ top = self.convertPoint([0, 0], toView:nil).y
356
+ height = window.frame.size.height - top
357
+ offset = CGPoint.new(0, height * 1.5)
358
+ offset = CGPointApplyAffineTransform(offset, self.transform)
359
+ self.transform = CGAffineTransformConcat(self.transform, CGAffineTransformMakeRotation(-Math::PI/4))
360
+ self.center = CGPointMake(self.center.x + offset.x, self.center.y + offset.y)
358
361
  }
359
362
  end
360
363
 
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.20.5'
2
+ Version = '0.20.6'
3
3
  end
@@ -26,5 +26,30 @@ describe "NSData" do
26
26
  it "should be able to create a turkey string from data" do
27
27
  "\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb".nsdata.nsstring.should == "\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb"
28
28
  end
29
+
30
+ describe "write_to" do
31
+
32
+ after do
33
+ "a-z".document.remove!
34
+ end
35
+
36
+ it "should write data to spcified path" do
37
+ path = "a-z".document
38
+ contents = (:a..:z).to_a.join
39
+ contents.nsdata.write_to(path).should == true
40
+ path.exists?.should == true
41
+ path.fileurl.nsdata.nsstring.should == contents
42
+ end
43
+
44
+ it "should write data to spcified url" do
45
+ url = NSURL.alloc.initFileURLWithPath "a-z".document
46
+ contents = (:a..:z).to_a.join
47
+ contents.nsdata.write_to(url).should == true
48
+ path = "a-z".document
49
+ path.exists?.should == true
50
+ url.nsdata.nsstring.should == contents
51
+ end
52
+
53
+ end
29
54
 
30
55
  end
@@ -74,6 +74,39 @@ describe 'NSString' do
74
74
  end
75
75
 
76
76
  end
77
+
78
+ describe "remove!" do
79
+
80
+ describe "in document" do
81
+ before do
82
+ "abc".writeToFile "abc".document, atomically:true
83
+ end
84
+ after do
85
+ NSFileManager.defaultManager.removeItemAtPath "abc".document, error:nil
86
+ end
87
+
88
+ it "should remove" do
89
+ "abc".remove!.should == nil
90
+ "abc".exists?.should == false
91
+ end
92
+ end
93
+
94
+ describe "in cache" do
95
+ before do
96
+ "abc".writeToFile "abc".cache, atomically:true
97
+ end
98
+ after do
99
+ NSFileManager.defaultManager.removeItemAtPath "abc".cache, error:nil
100
+ end
101
+
102
+ it "should remove" do
103
+ path = "abc".cache
104
+ path.remove!.should == nil
105
+ path.exists?.should == false
106
+ end
107
+ end
108
+
109
+ end
77
110
 
78
111
  describe 'resource()' do
79
112
  describe '"info.plist".resource' do
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: 0.20.5
4
+ version: 0.20.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-04-02 00:00:00.000000000 Z
16
+ date: 2013-04-04 00:00:00.000000000 Z
17
17
  dependencies: []
18
18
  description: ! '== Description
19
19