Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove instantiating Device as BW::Device #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Make sure to append onto the array or use `+=`.
```ruby
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
puts "#{App.name} (#{App.documents_path})"
puts "#{BW::App.name} (#{BW::App.documents_path})"
true
end
end
Expand Down Expand Up @@ -169,43 +169,43 @@ BubbleWrap.debug?
A module with useful methods related to the running application

```ruby
> App.documents_path
> BW::App.documents_path
# "/Users/mattetti/Library/Application Support/iPhone Simulator/5.0/Applications/EEC6454E-1816-451E-BB9A-EE18222E1A8F/Documents"
> App.resources_path
> BW::App.resources_path
# "/Users/mattetti/Library/Application Support/iPhone Simulator/5.0/Applications/EEC6454E-1816-451E-BB9A-EE18222E1A8F/testSuite_spec.app"
> App.name
> BW::App.name
# "testSuite"
> App.identifier
> BW::App.identifier
# "io.bubblewrap.testSuite"
> App.alert("BubbleWrap is awesome!")
> BW::App.alert("BubbleWrap is awesome!")
# creates and shows an alert message.
> App.alert("BubbleWrap is awesome!", {cancel_button_title: "I know it is!", message: "Like, seriously awesome."})
> BW::App.alert("BubbleWrap is awesome!", {cancel_button_title: "I know it is!", message: "Like, seriously awesome."})
# creates and shows an alert message with optional parameters.
> App.run_after(0.5) { p "It's #{Time.now}" }
> BW::App.run_after(0.5) { p "It's #{Time.now}" }
# Runs the block after 0.5 seconds.
> App.open_url("http://matt.aimonetti.net")
> BW::App.open_url("http://matt.aimonetti.net")
# Opens the url using the device's browser. (accepts a string url or an instance of `NSURL`.
> App::Persistence['channels'] # application specific persistence storage
> BW::App::Persistence['channels'] # application specific persistence storage
# ['NBC', 'ABC', 'Fox', 'CBS', 'PBS']
> App::Persistence['channels'] = ['TF1', 'France 2', 'France 3']
> BW::App::Persistence['channels'] = ['TF1', 'France 2', 'France 3']
# ['TF1', 'France 2', 'France 3']
> App.environment
> BW::App.environment
# 'test'
```

Other available methods:

* `App.notification_center`
* `App.user_cache`
* `App.states`
* `App.frame`
* `App.delegate`
* `App.shared`
* `App.window`
* `App.current_locale`
* `App.release?`
* `App.test?`
* `App.development?`
* `BW::App.notification_center`
* `BW::App.user_cache`
* `BW::App.states`
* `BW::App.frame`
* `BW::App.delegate`
* `BW::App.shared`
* `BW::App.window`
* `BW::App.current_locale`
* `BW::App.release?`
* `BW::App.test?`
* `BW::App.development?`


### Device
Expand All @@ -215,31 +215,31 @@ A collection of useful methods about the current device:
Examples:

```ruby
> Device.iphone?
> BW::Device.iphone?
# true
> Device.ipad?
> BW::Device.ipad?
# false
> Device.camera.front?
> BW::Device.camera.front?
# true
> Device.camera.rear?
> BW::Device.camera.rear?
# true
> Device.orientation
> BW::Device.orientation
# :portrait
> Device.interface_orientation
> BW::Device.interface_orientation
# :portrait
> Device.simulator?
> BW::Device.simulator?
# true
> Device.ios_version
> BW::Device.ios_version
# "6.0"
> Device.retina?
> BW::Device.retina?
# false
> Device.screen.width
> BW::Device.screen.width
# 320
> Device.screen.height
> BW::Device.screen.height
# 480
> Device.screen.width_for_orientation(:landscape_left)
> BW::Device.screen.width_for_orientation(:landscape_left)
# 480
> Device.screen.height_for_orientation(:landscape_left)
> BW::Device.screen.height_for_orientation(:landscape_left)
# 320
```

Expand Down Expand Up @@ -287,44 +287,44 @@ Helper methods to give NSNotificationCenter a Ruby-like interface:

```ruby
def viewWillAppear(animated)
@foreground_observer = App.notification_center.observe UIApplicationWillEnterForegroundNotification do |notification|
@foreground_observer = BW::App.notification_center.observe UIApplicationWillEnterForegroundNotification do |notification|
loadAndRefresh
end

@reload_observer = App.notification_center.observe 'ReloadNotification' do |notification|
@reload_observer = BW::App.notification_center.observe 'ReloadNotification' do |notification|
loadAndRefresh
end
end

def viewWillDisappear(animated)
App.notification_center.unobserve @foreground_observer
App.notification_center.unobserve @reload_observer
BW::App.notification_center.unobserve @foreground_observer
BW::App.notification_center.unobserve @reload_observer
end

def reload
App.notification_center.post 'ReloadNotification'
BW::App.notification_center.post 'ReloadNotification'
end
```


### NSUserDefaults

Helper methods added to the class repsonsible for user preferences used
by the `App::Persistence` module shown below.
by the `BW::App::Persistence` module shown below.

### Persistence

Offers a way to persist application specific information using a very
simple interface:

``` ruby
> App::Persistence['channels'] # application specific persistence storage
> BW::App::Persistence['channels'] # application specific persistence storage
# ['NBC', 'ABC', 'Fox', 'CBS', 'PBS']
> App::Persistence['channels'] = ['TF1', 'France 2', 'France 3']
> BW::App::Persistence['channels'] = ['TF1', 'France 2', 'France 3']
# ['TF1', 'France 2', 'France 3']
> App::Persistence.delete('channels')
> BW::App::Persistence.delete('channels')
# ['TF1', 'France 2', 'France 3']
> App::Persistence['something__new'] # something previously never stored
> BW::App::Persistence['something__new'] # something previously never stored
# nil
```

Expand Down Expand Up @@ -713,9 +713,9 @@ BW::HTTP.post("http://foo.bar.com/", {payload: data}) do |response|
json = BW::JSON.parse(response.body.to_str)
p json['id']
elsif response.status_code.to_s =~ /40\d/
App.alert("Login failed")
BW::App.alert("Login failed")
else
App.alert(response.error_message)
BW::App.alert(response.error_message)
end
end
```
Expand Down Expand Up @@ -765,7 +765,7 @@ class HttpClient
BW::HTTP.get(user_url(user_id)) do |response|
# ..
end
end
end
end
```

Expand Down
1 change: 0 additions & 1 deletion motion/core/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,3 @@ def ios?
end

end
::App = BubbleWrap::App unless defined?(::App)
1 change: 0 additions & 1 deletion motion/core/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ def retina?
end
end
end
::Device = BubbleWrap::Device unless defined?(::Device)
34 changes: 17 additions & 17 deletions spec/motion/core/app_spec.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
describe BubbleWrap::App do
describe '.documents_path' do
it 'should end in "/Documents"' do
App.documents_path[-10..-1].should == '/Documents'
BubbleWrap::App.documents_path[-10..-1].should == '/Documents'
end
end

describe '.resources_path' do
it 'should end in "/testSuite.app"' do
if App.osx?
App.resources_path.should =~ /\/testSuite(_spec)?.app\/Contents\/Resources$/
if BubbleWrap::App.osx?
BubbleWrap::App.resources_path.should =~ /\/testSuite(_spec)?.app\/Contents\/Resources$/
else
App.resources_path.should =~ /\/testSuite(_spec)?.app$/
BubbleWrap::App.resources_path.should =~ /\/testSuite(_spec)?.app$/
end
end
end

describe '.notification_center' do
it 'should be a NSNotificationCenter' do
App.notification_center.should == NSNotificationCenter.defaultCenter
BubbleWrap::App.notification_center.should == NSNotificationCenter.defaultCenter
end
end

describe '.user_cache' do
it 'should be a NSUserDefaults' do
App.user_cache.should == NSUserDefaults.standardUserDefaults
BubbleWrap::App.user_cache.should == NSUserDefaults.standardUserDefaults
end
end

describe '.states' do
it 'returns a hash' do
App.states.class.should == Hash
BubbleWrap::App.states.class.should == Hash
end
it "returns the real instance variable" do
App.states.should == App.instance_variable_get(:@states)
BubbleWrap::App.states.should == BubbleWrap::App.instance_variable_get(:@states)
end
end

describe '.info_plist' do
it 'returns the information property list hash' do
App.info_plist.should == NSBundle.mainBundle.infoDictionary
BubbleWrap::App.info_plist.should == NSBundle.mainBundle.infoDictionary
end
end

describe '.name' do
it 'returns the application name' do
App.name.should == 'testSuite'
BubbleWrap::App.name.should == 'testSuite'
end
end

describe '.identifier' do
it 'returns the application identifier' do
App.identifier.should == 'io.bubblewrap.testSuite_spec'
BubbleWrap::App.identifier.should == 'io.bubblewrap.testSuite_spec'
end
end

describe '.version' do
it 'returns the application version' do
App.version.should == '1.2.3'
BubbleWrap::App.version.should == '1.2.3'
end
end

Expand All @@ -66,7 +66,7 @@ class DelayedRunAfterTest; attr_accessor :test_value end
it 'should run a block after the provided delay' do
@test_obj = DelayedRunAfterTest.new

App.run_after(0.1){ @test_obj.test_value = true }
BubbleWrap::App.run_after(0.1){ @test_obj.test_value = true }
wait_for_change(@test_obj, 'test_value') do
@test_obj.test_value.should == true
end
Expand All @@ -77,23 +77,23 @@ class DelayedRunAfterTest; attr_accessor :test_value end
describe ".environment" do

it 'returns current application environment' do
App.environment.should.equal "test"
BubbleWrap::App.environment.should.equal "test"
end

end

describe ".test? .release? .development?" do

it 'tests if current application environment is test' do
App.test?.should.equal true
BubbleWrap::App.test?.should.equal true
end

it 'tests if current application environment is release' do
App.release?.should.equal false
BubbleWrap::App.release?.should.equal false
end

it 'tests if current application environment is development' do
App.development?.should.equal false
BubbleWrap::App.development?.should.equal false
end

end
Expand Down
Loading