motion-objection 0.6.4 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjRiNmUwZGFjYTc5YTI1NzhjMjZhNGY0N2RkMjBlNTA3ODlhMjk3Ng==
4
+ M2ZmMTNjMGY4YTI4NzhiYTRjYzM1MGFjNDRkNzYwNWQ2Zjk1ZTUzNw==
5
5
  data.tar.gz: !binary |-
6
- MTllOWVhZmIxMDJmZDdhODkzNTUxYmRhY2JhZThkNjAxNmU1ZDMzMA==
6
+ N2NkMTk5ZjUwMWNkMmZiNGU3YTBhOWM3ZmM0ZjgyMmEzZWM1NjMzOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YWYwNTU1OGU3Yjg4MjZhMDk2NDcyNjRmNDMwNzkxOTBhZjIwYTBmYjUxZDQ3
10
- ZDc0YzMyMTNkNGE0NmUyYTI0MjNiNDc2ODc4NDBlZDYyY2JjNDFiNTQxYTBm
11
- ZGM5ZWQxYTdlOGY0MTNlYTIxZGJmZWQzZmE1MDZmMDBiN2JhM2E=
9
+ YjNkYzhjODFhNjhkMzg5ZjA4ZDliMzg5MTk3MDI2MjNhYzQyYjliOWEyZTM1
10
+ MDQ1ZDIzMGEwODAzYjE4NDNhYmYxOTJhZjg2ZmM4NDIxYjk5MjFiYmVhNTkz
11
+ MWNjYzdjZmJiN2QxYzMzODY4NjllYzgzZTI1ZGMzMGI5NWM4ODE=
12
12
  data.tar.gz: !binary |-
13
- NjYyODg0NzQ4NTRjMTliMTg0MDE0MDFjYzUyYWI2NzQ0ZmE0YWE0ZDliMTIw
14
- NmI3YTUzYTI0MGFmYzYwZjMxOGI0NDg1MjQwNTIwYjM3OTA1ODQxZWQzZDc2
15
- OGZkNjFlYTg4NzcyMTA1ZWRkYjczMjQ1Yjk4ZWZkMGZmM2JiODI=
13
+ N2UxMTIwZGQ5MzZjNDdmOThhYmM5OTc0ODA4ZjBhYmVjZmY1ZmFhODk3NjI1
14
+ ZTUwMjhjMjJhYWI3YzU1Nzg1YzFmNGU3NmY4NmQ3YTI5NmZlNTdkMjI2MzNj
15
+ MDQyNDYyMDQ2ODRhMjU0OGM5ZDZmNjdmMDI4N2UxOWMzYThlYmU=
data/README.md CHANGED
@@ -1,50 +1,90 @@
1
1
  motion-objection
2
2
  ================
3
3
 
4
- Wrapping the dependency injection library [Objection](https://github.com/atomicobject/objection) in RubyMotion.
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
  <!-- [![Build Status](https://travis-ci.org/atomicobject/motion-objection.png)](https://travis-ci.org/atomicobject/motion-objection) -->
7
7
  [![Gem Version](https://badge.fury.io/rb/motion-objection.png)](http://badge.fury.io/rb/motion-objection)
8
8
  [![Code Climate](https://codeclimate.com/github/atomicobject/motion-objection.png)](https://codeclimate.com/github/atomicobject/motion-objection)
9
9
 
10
- ## Install
10
+ ## Installation
11
+
12
+
11
13
  ```bash
12
14
  gem install motion-objection
13
15
  ```
14
- ## Basic Example
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, factory: JSObjectFactory
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
- def brake!
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 < NSObject
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
- ## Default Injector
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
- Objection.default_injector = Objection.injector AppModule.new, SecondaryModule.new
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
@@ -1,10 +1,10 @@
1
1
  module Objection
2
2
  module Compose
3
- def self.included(base)
3
+ def self.included(base) #:nodoc:
4
4
  base.send :extend, ClassMethods
5
5
  end
6
6
 
7
- module Initializer
7
+ module Initializer #:nodoc:
8
8
  def objectionInitializer
9
9
  @_initializer
10
10
  end
@@ -1,3 +1,3 @@
1
- class JSObjection
1
+ class JSObjection #:nodoc:
2
2
  setPropertyReflector RubyPropertyReflector
3
3
  end
@@ -0,0 +1,3 @@
1
+ class NSObject
2
+ include Objection::Awoken
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Objection
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -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
- def awakeFromObjection
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
@@ -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.6.4
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-09 00:00:00.000000000 Z
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