bubble-wrap 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/README.md +26 -15
- data/Rakefile +3 -2
- data/lib/bubble-wrap.rb +2 -2
- data/lib/bubble-wrap/app.rb +58 -33
- data/lib/bubble-wrap/device.rb +66 -0
- data/lib/bubble-wrap/device/screen.rb +69 -0
- data/lib/bubble-wrap/gestures.rb +15 -14
- data/lib/bubble-wrap/http.rb +25 -19
- data/lib/bubble-wrap/module.rb +24 -0
- data/lib/bubble-wrap/ns_notification_center.rb +8 -10
- data/lib/bubble-wrap/persistence.rb +27 -0
- data/lib/bubble-wrap/time.rb +8 -0
- data/lib/bubble-wrap/{ui_button.rb → ui_control.rb} +1 -1
- data/lib/bubble-wrap/version.rb +1 -1
- data/lib/pollute.rb +1 -1
- data/lib/tests/test_suite_delegate.rb +2 -0
- data/spec/app_spec.rb +83 -0
- data/spec/device/screen_spec.rb +153 -0
- data/spec/device_spec.rb +112 -0
- data/spec/gestures_spec.rb +51 -0
- data/spec/http_spec.rb +363 -0
- data/spec/json_spec.rb +0 -2
- data/spec/module_spec.rb +2 -0
- data/spec/ns_index_path_spec.rb +8 -6
- data/spec/ns_notification_center_spec.rb +14 -9
- data/spec/persistence_spec.rb +20 -0
- data/spec/time_spec.rb +41 -0
- data/spec/{ui_button_spec.rb → ui_control_spec.rb} +11 -1
- metadata +24 -6
- data/lib/bubble-wrap/kernel.rb +0 -105
@@ -1,32 +1,37 @@
|
|
1
1
|
describe "NSNotificationCenter" do
|
2
2
|
SampleNotification = "SampleNotification"
|
3
|
+
|
3
4
|
after do
|
4
|
-
@observer =
|
5
|
+
@observer = nil
|
5
6
|
end
|
6
7
|
|
7
8
|
after do
|
8
|
-
notification_center.unobserve(@observer)
|
9
|
+
BW::App.notification_center.unobserve(@observer) if @observer
|
9
10
|
end
|
10
11
|
|
11
12
|
it "return notification center" do
|
12
|
-
notification_center.should.not.be.nil
|
13
|
+
BW::App.notification_center.should.not.be.nil
|
13
14
|
end
|
14
15
|
|
15
16
|
it "add observer" do
|
16
17
|
notified = false
|
17
|
-
notification_center.observe(
|
18
|
+
@observer = BW::App.notification_center.observe(SampleNotification) do |note|
|
18
19
|
notified = true
|
20
|
+
note.should.is_a NSNotification
|
21
|
+
note.object.class.should == Time
|
22
|
+
note.userInfo.should.not.be.nil
|
23
|
+
note.userInfo[:status].should == "ok"
|
19
24
|
end
|
20
25
|
|
21
26
|
lambda {
|
22
|
-
notification_center.post SampleNotification
|
27
|
+
BW::App.notification_center.post SampleNotification, Time.now, {:status => "ok"}
|
23
28
|
}.should.change { notified }
|
24
29
|
end
|
25
30
|
|
26
31
|
it "remove observer" do
|
27
32
|
lambda {
|
28
|
-
notification_center.observe(
|
29
|
-
notification_center.unobserve(@observer)
|
30
|
-
}.should.not.change { notification_center.observers.
|
33
|
+
@observer = BW::App.notification_center.observe(SampleNotification) {}
|
34
|
+
BW::App.notification_center.unobserve(@observer)
|
35
|
+
}.should.not.change { BW::App.notification_center.observers.size }
|
31
36
|
end
|
32
|
-
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
describe BubbleWrap::Persistence do
|
2
|
+
|
3
|
+
describe '.app_key' do
|
4
|
+
it 'delegates to BubbleWrap::App.idenfitier' do
|
5
|
+
BubbleWrap::Persistence.app_key.should == BubbleWrap::App.identifier
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can persist simple objects' do
|
10
|
+
lambda do
|
11
|
+
BubbleWrap::Persistence['arbitraryNumber'] = 42
|
12
|
+
end.
|
13
|
+
should.not.raise(Exception)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can retrieve persisted objects' do
|
17
|
+
BubbleWrap::Persistence['arbitraryNumber'].should == 42
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/time_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
describe "Time" do
|
2
|
+
|
3
|
+
describe "parsing an iso8601 formatted time to a Time object" do
|
4
|
+
before do
|
5
|
+
@time = Time.iso8601("2012-05-31T19:41:33Z")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be a time" do
|
9
|
+
@time.instance_of?(Time).should == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be converted to the local timezone automatically" do
|
13
|
+
@time.zone.should == Time.now.zone
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a valid year" do
|
17
|
+
@time.utc.year.should == 2012
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a valid month" do
|
21
|
+
@time.utc.month.should == 5
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have a valid day" do
|
25
|
+
@time.utc.day.should == 31
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have a valid hour" do
|
29
|
+
@time.utc.hour.should == 19
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have a valid minute" do
|
33
|
+
@time.utc.min.should == 41
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have a valid second" do
|
37
|
+
@time.utc.sec.should == 33
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe "
|
1
|
+
describe "UIControlWrap" do
|
2
2
|
|
3
3
|
it "should support the 'when' event handler" do
|
4
4
|
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
|
@@ -9,4 +9,14 @@ describe "UIButton" do
|
|
9
9
|
button.sendActionsForControlEvents(UIControlEventTouchUpInside)
|
10
10
|
touched.should == 'for the very first time'
|
11
11
|
end
|
12
|
+
|
13
|
+
it "should support the 'when' event handler for UISlider" do
|
14
|
+
button = UISlider.alloc.init
|
15
|
+
changed = nil
|
16
|
+
button.when(UIControlEventValueChanged) do
|
17
|
+
changed = 1
|
18
|
+
end
|
19
|
+
button.sendActionsForControlEvents(UIControlEventValueChanged)
|
20
|
+
changed.should == 1
|
21
|
+
end
|
12
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bubble-wrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-03 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: RubyMotion wrappers and helpers (Ruby for iOS) - Making Cocoa APIs more
|
16
16
|
Ruby like, one API at a time. Fork away and send your pull request.
|
@@ -30,23 +30,34 @@ files:
|
|
30
30
|
- bubble-wrap.gemspec
|
31
31
|
- lib/bubble-wrap.rb
|
32
32
|
- lib/bubble-wrap/app.rb
|
33
|
+
- lib/bubble-wrap/device.rb
|
34
|
+
- lib/bubble-wrap/device/screen.rb
|
33
35
|
- lib/bubble-wrap/gestures.rb
|
34
36
|
- lib/bubble-wrap/http.rb
|
35
37
|
- lib/bubble-wrap/json.rb
|
36
|
-
- lib/bubble-wrap/
|
38
|
+
- lib/bubble-wrap/module.rb
|
37
39
|
- lib/bubble-wrap/ns_index_path.rb
|
38
40
|
- lib/bubble-wrap/ns_notification_center.rb
|
39
41
|
- lib/bubble-wrap/ns_user_defaults.rb
|
40
|
-
- lib/bubble-wrap/
|
42
|
+
- lib/bubble-wrap/persistence.rb
|
43
|
+
- lib/bubble-wrap/time.rb
|
44
|
+
- lib/bubble-wrap/ui_control.rb
|
41
45
|
- lib/bubble-wrap/ui_view_controller.rb
|
42
46
|
- lib/bubble-wrap/version.rb
|
43
47
|
- lib/pollute.rb
|
44
48
|
- lib/tests/test_suite_delegate.rb
|
49
|
+
- spec/app_spec.rb
|
50
|
+
- spec/device/screen_spec.rb
|
51
|
+
- spec/device_spec.rb
|
52
|
+
- spec/gestures_spec.rb
|
45
53
|
- spec/http_spec.rb
|
46
54
|
- spec/json_spec.rb
|
55
|
+
- spec/module_spec.rb
|
47
56
|
- spec/ns_index_path_spec.rb
|
48
57
|
- spec/ns_notification_center_spec.rb
|
49
|
-
- spec/
|
58
|
+
- spec/persistence_spec.rb
|
59
|
+
- spec/time_spec.rb
|
60
|
+
- spec/ui_control_spec.rb
|
50
61
|
- spec_helper_patch.diff
|
51
62
|
homepage: https://github.com/mattetti/BubbleWrap
|
52
63
|
licenses: []
|
@@ -74,8 +85,15 @@ specification_version: 3
|
|
74
85
|
summary: RubyMotion wrappers and helpers (Ruby for iOS) - Making Cocoa APIs more Ruby
|
75
86
|
like, one API at a time. Fork away and send your pull request.
|
76
87
|
test_files:
|
88
|
+
- spec/app_spec.rb
|
89
|
+
- spec/device/screen_spec.rb
|
90
|
+
- spec/device_spec.rb
|
91
|
+
- spec/gestures_spec.rb
|
77
92
|
- spec/http_spec.rb
|
78
93
|
- spec/json_spec.rb
|
94
|
+
- spec/module_spec.rb
|
79
95
|
- spec/ns_index_path_spec.rb
|
80
96
|
- spec/ns_notification_center_spec.rb
|
81
|
-
- spec/
|
97
|
+
- spec/persistence_spec.rb
|
98
|
+
- spec/time_spec.rb
|
99
|
+
- spec/ui_control_spec.rb
|
data/lib/bubble-wrap/kernel.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
|
3
|
-
# Verifies that the device running the app is an iPhone.
|
4
|
-
# @return [TrueClass, FalseClass] true will be returned if the device is an iPhone, false otherwise.
|
5
|
-
def iphone?
|
6
|
-
UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone
|
7
|
-
end
|
8
|
-
|
9
|
-
# Verifies that the device running the app is an iPad.
|
10
|
-
# @return [TrueClass, FalseClass] true will be returned if the device is an iPad, false otherwise.
|
11
|
-
def ipad?
|
12
|
-
UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
|
13
|
-
end
|
14
|
-
|
15
|
-
# Certifies that the device running the app has a Retina display
|
16
|
-
# @return [TrueClass, FalseClass] true will be returned if the device has a Retina display, false otherwise.
|
17
|
-
def retina?
|
18
|
-
if UIScreen.mainScreen.respondsToSelector('displayLinkWithTarget:selector:') && UIScreen.mainScreen.scale == 2.0
|
19
|
-
true
|
20
|
-
else
|
21
|
-
false
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Verifies that the device running has a front facing camera.
|
26
|
-
# @return [TrueClass, FalseClass] true will be returned if the device has a front facing camera, false otherwise.
|
27
|
-
def front_camera?
|
28
|
-
UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDeviceFront)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Verifies that the device running has a rear facing camera.
|
32
|
-
# @return [TrueClass, FalseClass] true will be returned if the device has a rear facing camera, false otherwise.
|
33
|
-
def rear_camera?
|
34
|
-
UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDeviceRear)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns the application's document directory path where users might be able to upload content.
|
38
|
-
# @return [String] the path to the document directory
|
39
|
-
def documents_path
|
40
|
-
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns the application resource path where resource located
|
44
|
-
# @return [String] the application main bundle resource path
|
45
|
-
def resources_path
|
46
|
-
NSBundle.mainBundle.resourcePath
|
47
|
-
end
|
48
|
-
|
49
|
-
# Returns the default notification center
|
50
|
-
# @return [NSNotificationCenter] the default notification center
|
51
|
-
def notification_center
|
52
|
-
NSNotificationCenter.defaultCenter
|
53
|
-
end
|
54
|
-
|
55
|
-
def orientation
|
56
|
-
case UIDevice.currentDevice.orientation
|
57
|
-
when UIDeviceOrientationUnknown then :unknown
|
58
|
-
when UIDeviceOrientationPortrait then :portrait
|
59
|
-
when UIDeviceOrientationPortraitUpsideDown then :portrait_upside_down
|
60
|
-
when UIDeviceOrientationLandscapeLeft then :landscape_left
|
61
|
-
when UIDeviceOrientationLandscapeRight then :landscape_right
|
62
|
-
when UIDeviceOrientationFaceUp then :face_up
|
63
|
-
when UIDeviceOrientationFaceDown then :face_down
|
64
|
-
else
|
65
|
-
:unknown
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# @return [UIcolor]
|
70
|
-
def rgb_color(r,g,b)
|
71
|
-
rgba_color(r,g,b,1)
|
72
|
-
end
|
73
|
-
|
74
|
-
# @return [UIcolor]
|
75
|
-
def rgba_color(r,g,b,a)
|
76
|
-
UIColor.colorWithRed((r/255.0), green:(g/255.0), blue:(b/255.0), alpha:a)
|
77
|
-
end
|
78
|
-
|
79
|
-
def NSLocalizedString(key, value)
|
80
|
-
NSBundle.mainBundle.localizedStringForKey(key, value:value, table:nil)
|
81
|
-
end
|
82
|
-
|
83
|
-
def user_cache
|
84
|
-
NSUserDefaults.standardUserDefaults
|
85
|
-
end
|
86
|
-
|
87
|
-
def alert(msg)
|
88
|
-
alert = UIAlertView.alloc.initWithTitle msg,
|
89
|
-
message: nil,
|
90
|
-
delegate: nil,
|
91
|
-
cancelButtonTitle: "OK",
|
92
|
-
otherButtonTitles: nil
|
93
|
-
alert.show
|
94
|
-
end
|
95
|
-
|
96
|
-
def simulator?
|
97
|
-
@simulator_state ||= !(UIDevice.currentDevice.model =~ /simulator/i).nil?
|
98
|
-
end
|
99
|
-
|
100
|
-
# I had issues with #p on the device, this is a temporary workaround
|
101
|
-
def p(arg)
|
102
|
-
NSLog arg.inspect
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|