motion-objection 0.6.4 → 0.7.1
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.
- checksums.yaml +8 -8
- data/README.md +94 -14
- data/lib/motion-objection/awoken.rb +27 -0
- data/lib/motion-objection/compose.rb +2 -2
- data/lib/motion-objection/{jsobjection.rb → extensions/js_objection.rb} +1 -1
- data/lib/motion-objection/{jsobjection_injector.rb → extensions/js_objection_injector.rb} +0 -0
- data/lib/motion-objection/extensions/ns_object.rb +3 -0
- data/lib/motion-objection/{string.rb → extensions/string.rb} +0 -0
- data/lib/motion-objection/version.rb +1 -1
- data/spec/helpers/objection_classes.rb +12 -1
- data/spec/objection_spec.rb +2 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2ZmMTNjMGY4YTI4NzhiYTRjYzM1MGFjNDRkNzYwNWQ2Zjk1ZTUzNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2NkMTk5ZjUwMWNkMmZiNGU3YTBhOWM3ZmM0ZjgyMmEzZWM1NjMzOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjNkYzhjODFhNjhkMzg5ZjA4ZDliMzg5MTk3MDI2MjNhYzQyYjliOWEyZTM1
|
10
|
+
MDQ1ZDIzMGEwODAzYjE4NDNhYmYxOTJhZjg2ZmM4NDIxYjk5MjFiYmVhNTkz
|
11
|
+
MWNjYzdjZmJiN2QxYzMzODY4NjllYzgzZTI1ZGMzMGI5NWM4ODE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2UxMTIwZGQ5MzZjNDdmOThhYmM5OTc0ODA4ZjBhYmVjZmY1ZmFhODk3NjI1
|
14
|
+
ZTUwMjhjMjJhYWI3YzU1Nzg1YzFmNGU3NmY4NmQ3YTI5NmZlNTdkMjI2MzNj
|
15
|
+
MDQyNDYyMDQ2ODRhMjU0OGM5ZDZmNjdmMDI4N2UxOWMzYThlYmU=
|
data/README.md
CHANGED
@@ -1,50 +1,90 @@
|
|
1
1
|
motion-objection
|
2
2
|
================
|
3
3
|
|
4
|
-
|
4
|
+
Motion-objection wraps the Objective-C dependency injection library [Objection](https://github.com/atomicobject/objection) in Ruby so that it can be used in [RubyMotion](http://www.rubymotion.com/). It has all of the power (and speed) of Objection and the declarative affordances that the Ruby language provides.
|
5
5
|
|
6
6
|
<!-- [](https://travis-ci.org/atomicobject/motion-objection) -->
|
7
7
|
[](http://badge.fury.io/rb/motion-objection)
|
8
8
|
[](https://codeclimate.com/github/atomicobject/motion-objection)
|
9
9
|
|
10
|
-
##
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
|
11
13
|
```bash
|
12
14
|
gem install motion-objection
|
13
15
|
```
|
14
|
-
|
16
|
+
|
17
|
+
## Basic Usage
|
18
|
+
|
19
|
+
A class can declare requires component objects by mixing in <code>Objection::Compose</code> and calling the <code>.compose_with</code> method
|
15
20
|
|
16
21
|
```ruby
|
17
22
|
class Car
|
18
23
|
include Objection::Compose
|
19
|
-
compose_with :engine, :brakes
|
24
|
+
compose_with :engine, :brakes
|
20
25
|
end
|
26
|
+
```
|
27
|
+
|
28
|
+
Where <code>:engine</code> and <code>:brakes</code> are assumed to be the <code>Engine</code> and <code>Brakes</code> classes. Classes that are namespaced can be declared as well by separating the namespaces using the <code>/</code> character.
|
21
29
|
|
30
|
+
```ruby
|
22
31
|
class Engine
|
23
32
|
include Objection::Compose
|
24
|
-
singleton
|
25
33
|
compose_with 'engine/crank_shaft', 'engine/rod'
|
26
34
|
|
27
|
-
def shift(wat)
|
28
|
-
puts "SHIFT!"
|
29
|
-
end
|
30
|
-
|
31
35
|
class CrankShaft
|
32
36
|
end
|
33
37
|
|
34
38
|
class Rod
|
35
39
|
end
|
36
40
|
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Sometimes you may need to declare the component object _and_ the class that is associated with it.
|
37
44
|
|
45
|
+
```ruby
|
38
46
|
class Brakes
|
39
|
-
|
47
|
+
compose_with factory: JSObjectFactory
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## Singletons
|
52
|
+
|
53
|
+
Singletons can be declared by calling the <code>.singleton</code> method in the class body. Singletons should really only be necessary if they contain _shared state_. Otherwise it behooves you to avoid singletons in order to reduce the memory footprint of an application.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class Holder
|
57
|
+
include Objection::Compose
|
58
|
+
singleton
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
## Awaking from Objection
|
63
|
+
|
64
|
+
Since Objection utilizes _setter_ based injection the initializer does not guarentee that all the object's dependencies have been satisfied.
|
65
|
+
|
66
|
+
The `awoke` class method can be given a block which will be invoked once the object has been fully instantiated.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
class Ship
|
70
|
+
awoke do
|
71
|
+
# Bootstrap listeners
|
72
|
+
end
|
73
|
+
|
74
|
+
awoke do
|
75
|
+
# Setup other stuff
|
40
76
|
end
|
41
77
|
end
|
42
78
|
```
|
43
79
|
|
44
|
-
## Initializers
|
80
|
+
## Default Initializers
|
81
|
+
|
82
|
+
Objection uses [Key-Value Coding](http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html) to compose an instance with its dependencies -- it does not use initializer injection.
|
83
|
+
|
84
|
+
By default Objection initializes an object using the <code>init</code> initializer. A custom initializer can be declared using the <code>.initializer</code> method.
|
45
85
|
|
46
86
|
```ruby
|
47
|
-
class ViewController <
|
87
|
+
class ViewController < UIViewController
|
48
88
|
include Objection::Compose
|
49
89
|
initializer "initWithNibName:bundle:", "Home"
|
50
90
|
|
@@ -59,8 +99,48 @@ class ViewController < NSObject
|
|
59
99
|
end
|
60
100
|
```
|
61
101
|
|
62
|
-
##
|
102
|
+
## Modules
|
103
|
+
|
104
|
+
Modules contribution configuration information to the Injector. Typically, this includes bindings for dependencies that the Injector cannot provide. For example, <code>UIApplication.sharedApplication</code> or the main application window.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
class AppModule < JSObjectionModule
|
108
|
+
def initialize(window, application: application)
|
109
|
+
@window = window
|
110
|
+
@application = application
|
111
|
+
end
|
112
|
+
|
113
|
+
def configure
|
114
|
+
bind @window, toClass: UIWindow
|
115
|
+
bind @application, toClass: UIApplication
|
116
|
+
end
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
There are a number of other configuration methods a module [provides](https://github.com/atomicobject/objection#modules).
|
121
|
+
|
122
|
+
## Bootstraping an Application
|
123
|
+
|
124
|
+
Typically an application is bootstrapped in the application delegate where an injector is created and set as the default injector via <code>.default_injector=</code>.
|
63
125
|
|
64
126
|
```ruby
|
65
|
-
|
127
|
+
class AppDelegate
|
128
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
129
|
+
initialize_objection
|
130
|
+
Objection.default_injector[ApplicationBootstrapper].bootstrap!
|
131
|
+
true
|
132
|
+
end
|
133
|
+
|
134
|
+
def initialize_objection
|
135
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
136
|
+
injector = Objection.injector(BankersDashboardModule.new(@window, UIApplication.sharedApplication))
|
137
|
+
Objection.default_injector = injector
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class ApplicationBootstrapper
|
142
|
+
def bootstrap!
|
143
|
+
# Bootstrap
|
144
|
+
end
|
145
|
+
end
|
66
146
|
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Objection
|
2
|
+
module Awoken
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def awakeFromObjection
|
10
|
+
# self.send :awoke_from_objection if self.respond_to? :awoke_from_objection
|
11
|
+
if self.class._incantations
|
12
|
+
self.class._incantations.each do |proc|
|
13
|
+
instance_eval &proc
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
attr_reader :_incantations
|
21
|
+
def awoken(&block)
|
22
|
+
@_incantations ||= []
|
23
|
+
@_incantations << block
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
File without changes
|
@@ -1,16 +1,27 @@
|
|
1
1
|
class Car
|
2
2
|
include Objection::Compose
|
3
|
+
attr_reader :started
|
3
4
|
compose_with :engine, :brakes, factory: JSObjectFactory
|
5
|
+
|
4
6
|
end
|
5
7
|
|
6
8
|
class EagerCar
|
7
9
|
include Objection::Compose
|
8
10
|
singleton
|
9
11
|
class<<self; attr_accessor :awoke; end
|
12
|
+
attr_accessor :awoke
|
13
|
+
|
14
|
+
def boom
|
15
|
+
puts @boom
|
16
|
+
end
|
10
17
|
|
11
|
-
|
18
|
+
awoken do
|
12
19
|
self.class.awoke = true
|
13
20
|
end
|
21
|
+
|
22
|
+
awoken do
|
23
|
+
self.awoke = true
|
24
|
+
end
|
14
25
|
end
|
15
26
|
|
16
27
|
class Engine
|
data/spec/objection_spec.rb
CHANGED
@@ -69,7 +69,9 @@ describe "Objection" do
|
|
69
69
|
|
70
70
|
it "has support for eager singletons" do
|
71
71
|
@injector = Objection.injector EagerSingletonModule.new
|
72
|
+
|
72
73
|
EagerCar.awoke.should.equal true
|
74
|
+
@injector[EagerCar].awoke.should.equal true
|
73
75
|
end
|
74
76
|
|
75
77
|
it "has support for an injector with a module" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-objection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin DeWind
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: motion-cocoapods
|
@@ -40,13 +40,15 @@ files:
|
|
40
40
|
- Rakefile
|
41
41
|
- app/app_delegate.rb
|
42
42
|
- lib/motion-objection.rb
|
43
|
+
- lib/motion-objection/awoken.rb
|
43
44
|
- lib/motion-objection/compose.rb
|
45
|
+
- lib/motion-objection/extensions/js_objection.rb
|
46
|
+
- lib/motion-objection/extensions/js_objection_injector.rb
|
47
|
+
- lib/motion-objection/extensions/ns_object.rb
|
48
|
+
- lib/motion-objection/extensions/string.rb
|
44
49
|
- lib/motion-objection/inflector.rb
|
45
|
-
- lib/motion-objection/jsobjection.rb
|
46
|
-
- lib/motion-objection/jsobjection_injector.rb
|
47
50
|
- lib/motion-objection/objection.rb
|
48
51
|
- lib/motion-objection/ruby_property_reflector.rb
|
49
|
-
- lib/motion-objection/string.rb
|
50
52
|
- lib/motion-objection/version.rb
|
51
53
|
- motion_objection.gemspec
|
52
54
|
- resources/Default-568h@2x.png
|