motion-objection 0.6.3 → 0.6.4

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
- YmY1MDA5MTVkNjJkY2UyNGU4MDY2YTZmNmRmNzEzZDYxYTRiNzgzMA==
4
+ NjRiNmUwZGFjYTc5YTI1NzhjMjZhNGY0N2RkMjBlNTA3ODlhMjk3Ng==
5
5
  data.tar.gz: !binary |-
6
- N2IzYWZmNjBjODkxNGMxYzg1MjFjZTM2ZmE0MTNmZDBiMWRlY2E3MQ==
6
+ MTllOWVhZmIxMDJmZDdhODkzNTUxYmRhY2JhZThkNjAxNmU1ZDMzMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzZkZjM0YmQyOTc3OTM1OWJkMDIyODg4YjJmZTczMWIwNTg4YTJhNGEwMGU1
10
- YmJkNDkzYjdlYmVlY2EzZWFjN2E5ZGJmY2QwZGIxZjFkOGFlMmUwNzBhZGQy
11
- OTAyYzgzYTU4MTM1ODIyZDljODU3MTQwMDgxOGYyNzFkZWJhZjI=
9
+ YWYwNTU1OGU3Yjg4MjZhMDk2NDcyNjRmNDMwNzkxOTBhZjIwYTBmYjUxZDQ3
10
+ ZDc0YzMyMTNkNGE0NmUyYTI0MjNiNDc2ODc4NDBlZDYyY2JjNDFiNTQxYTBm
11
+ ZGM5ZWQxYTdlOGY0MTNlYTIxZGJmZWQzZmE1MDZmMDBiN2JhM2E=
12
12
  data.tar.gz: !binary |-
13
- YjRjYzI3MTA5YjkzYjliZmMyZjkyMTVhM2ViMmU2OTg1YmE0MTAzZWMwODg4
14
- NDBlZTg3OTA1NWE2NWRlNWI5YWM5YTgwNDczNDg4MmE5OTQ3NDNlZDNjZjU1
15
- MzU0ZDAwOTQ3ZDIyMzc4MzhkNzQyZTg5Njk3NWQ2MDFkNWYzMGY=
13
+ NjYyODg0NzQ4NTRjMTliMTg0MDE0MDFjYzUyYWI2NzQ0ZmE0YWE0ZDliMTIw
14
+ NmI3YTUzYTI0MGFmYzYwZjMxOGI0NDg1MjQwNTIwYjM3OTA1ODQxZWQzZDc2
15
+ OGZkNjFlYTg4NzcyMTA1ZWRkYjczMjQ1Yjk4ZWZkMGZmM2JiODI=
data/README.md CHANGED
@@ -3,7 +3,7 @@ motion-objection
3
3
 
4
4
  Wrapping the dependency injection library [Objection](https://github.com/atomicobject/objection) in RubyMotion.
5
5
 
6
- [![Build Status](https://travis-ci.org/atomicobject/motion-objection.png)](https://travis-ci.org/atomicobject/motion-objection)
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
 
@@ -15,12 +15,12 @@ gem install motion-objection
15
15
 
16
16
  ```ruby
17
17
  class Car
18
- include Objection
18
+ include Objection::Compose
19
19
  compose_with :engine, :brakes, factory: JSObjectFactory
20
20
  end
21
21
 
22
22
  class Engine
23
- include Objection
23
+ include Objection::Compose
24
24
  singleton
25
25
  compose_with 'engine/crank_shaft', 'engine/rod'
26
26
 
@@ -45,7 +45,7 @@ end
45
45
 
46
46
  ```ruby
47
47
  class ViewController < NSObject
48
- include Objection
48
+ include Objection::Compose
49
49
  initializer "initWithNibName:bundle:", "Home"
50
50
 
51
51
  attr_reader :name
@@ -62,5 +62,5 @@ end
62
62
  ## Default Injector
63
63
 
64
64
  ```ruby
65
- Objection.default_injector = Objection.injector
65
+ Objection.default_injector = Objection.injector AppModule.new, SecondaryModule.new
66
66
  ```
data/Rakefile CHANGED
@@ -9,7 +9,9 @@ require './lib/motion-objection'
9
9
  Motion::Project::App.setup do |app|
10
10
  # Use `rake config' to see complete project settings.
11
11
  app.name = 'motion-objection'
12
+
12
13
  app.identifier = 'com.atomicobject.motion-objection'
14
+
13
15
  app.pods do
14
16
  pod "Objection", "~>1.0.3"
15
17
  end
@@ -0,0 +1,70 @@
1
+ module Objection
2
+ module Compose
3
+ def self.included(base)
4
+ base.send :extend, ClassMethods
5
+ end
6
+
7
+ module Initializer
8
+ def objectionInitializer
9
+ @_initializer
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ def compose_with(*args)
16
+ @_type_mappings = {}
17
+ properties = []
18
+ args.each do |arg|
19
+ if arg.is_a? Hash
20
+ arg.each do |k,v|
21
+ @_type_mappings[k.to_s] = v
22
+ attr_accessor k
23
+ properties << k
24
+ end
25
+ else
26
+ prop = arg.split("/").last
27
+ attr_accessor prop
28
+ @_type_mappings[prop] = arg.to_s
29
+ properties << prop
30
+ end
31
+ end
32
+ @_dependencies = NSSet.setWithArray(properties.map(&:to_s))
33
+ end
34
+
35
+ def singleton
36
+ JSObjection.registerClass self, scope: JSObjectionScopeSingleton
37
+ end
38
+
39
+ def initializer(selector, *args)
40
+ self.send :extend, Initializer
41
+ @_initializer = {
42
+ "initializer" => selector,
43
+ "arguments" => args
44
+ }
45
+ end
46
+
47
+ protected
48
+
49
+ def objectionRequires
50
+ @_dependencies ||= NSSet.set
51
+ if self.superclass.respondsToSelector :objectionRequires
52
+ set = NSMutableSet.setWithSet self.superclass.objectionRequires
53
+ set.unionSet @_dependencies
54
+ set
55
+ else
56
+ @_dependencies
57
+ end
58
+ end
59
+
60
+ def objectionTypeMappings
61
+ @_type_mappings ||= {}
62
+ if self.superclass.respondsToSelector :objectionTypeMappings
63
+ @_type_mappings.merge self.superclass.objectionTypeMappings
64
+ else
65
+ @_type_mappings
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,10 +1,7 @@
1
1
  module Objection
2
+ module_function
2
3
 
3
- def self.included(base)
4
- base.send :extend, ClassMethods
5
- end
6
-
7
- def self.injector(*modules)
4
+ def injector(*modules)
8
5
  if modules.empty?
9
6
  JSObjection.createInjector
10
7
  elsif modules.size == 1
@@ -14,74 +11,11 @@ module Objection
14
11
  end
15
12
  end
16
13
 
17
- def self.default_injector=(injector)
14
+ def default_injector=(injector)
18
15
  JSObjection.setDefaultInjector injector
19
16
  end
20
17
 
21
- def self.default_injector
18
+ def default_injector
22
19
  JSObjection.defaultInjector
23
20
  end
24
-
25
- module Initializer
26
- def objectionInitializer
27
- @_initializer
28
- end
29
- end
30
-
31
- module ClassMethods
32
-
33
- def compose_with(*args)
34
- @_type_mappings = {}
35
- properties = []
36
- args.each do |arg|
37
- if arg.is_a? Hash
38
- arg.each do |k,v|
39
- @_type_mappings[k.to_s] = v
40
- attr_accessor k
41
- properties << k
42
- end
43
- else
44
- prop = arg.split("/").last
45
- attr_accessor prop
46
- @_type_mappings[prop] = arg.to_s
47
- properties << prop
48
- end
49
- end
50
- @_dependencies = NSSet.setWithArray(properties.map(&:to_s))
51
- end
52
-
53
- def singleton
54
- JSObjection.registerClass self, scope: JSObjectionScopeSingleton
55
- end
56
-
57
- def initializer(selector, *args)
58
- self.send :extend, Initializer
59
- @_initializer = {
60
- "initializer" => selector,
61
- "arguments" => args
62
- }
63
- end
64
-
65
- protected
66
-
67
- def objectionRequires
68
- @_dependencies ||= NSSet.set
69
- if self.superclass.respondsToSelector :objectionRequires
70
- set = NSMutableSet.setWithSet self.superclass.objectionRequires
71
- set.unionSet @_dependencies
72
- set
73
- else
74
- @_dependencies
75
- end
76
- end
77
-
78
- def objectionTypeMappings
79
- @_type_mappings ||= {}
80
- if self.superclass.respondsToSelector :objectionTypeMappings
81
- @_type_mappings.merge self.superclass.objectionTypeMappings
82
- else
83
- @_type_mappings
84
- end
85
- end
86
- end
87
21
  end
@@ -1,3 +1,3 @@
1
1
  module Objection
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -1,10 +1,20 @@
1
1
  class Car
2
- include Objection
3
- compose_with :engine, :brakes, factory: JSObjectFactory
2
+ include Objection::Compose
3
+ compose_with :engine, :brakes, factory: JSObjectFactory
4
+ end
5
+
6
+ class EagerCar
7
+ include Objection::Compose
8
+ singleton
9
+ class<<self; attr_accessor :awoke; end
10
+
11
+ def awakeFromObjection
12
+ self.class.awoke = true
13
+ end
4
14
  end
5
15
 
6
16
  class Engine
7
- include Objection
17
+ include Objection::Compose
8
18
  singleton
9
19
  compose_with 'engine/crank_shaft', 'engine/rod'
10
20
 
@@ -19,7 +29,9 @@ class Engine
19
29
  end
20
30
  end
21
31
 
22
- class V6Engine < Engine; end
32
+ class V6Engine < Engine
33
+ compose_with factory: JSObjectFactory
34
+ end
23
35
 
24
36
  class Brakes
25
37
  def brake!
@@ -32,7 +44,7 @@ class ABSBrakes < Brakes
32
44
  end
33
45
 
34
46
  class ViewController < NSObject
35
- include Objection
47
+ include Objection::Compose
36
48
  initializer "initWithNibName:bundle:", "Home"
37
49
 
38
50
  attr_reader :name
@@ -17,3 +17,9 @@ class AppModuleII < JSObjectionModule
17
17
  bindClass ABSBrakes, toClass: Brakes
18
18
  end
19
19
  end
20
+
21
+ class EagerSingletonModule < JSObjectionModule
22
+ def configure
23
+ registerEagerSingleton EagerCar
24
+ end
25
+ end
@@ -11,12 +11,25 @@ describe "Objection" do
11
11
  end
12
12
  end
13
13
 
14
+ describe "#inject_dependencies" do
15
+ it "injects dependencies into an object constructed outside of objection" do
16
+ @engine = V6Engine.new
17
+
18
+ @engine.crank_shaft.should.equal nil
19
+
20
+ @injector.inject_dependencies @engine
21
+
22
+ @engine.crank_shaft.class.should.be.same_as Engine::CrankShaft
23
+ end
24
+ end
25
+
14
26
  describe "dependency injection" do
15
27
  it "supports inheritance" do
16
28
  @engine = @injector[V6Engine]
17
29
 
18
30
  @engine.crank_shaft.class.should.be.same_as Engine::CrankShaft
19
31
  @engine.rod.class.should.be.same_as Engine::Rod
32
+ @engine.factory.class.should.be.same_as JSObjectFactory
20
33
  end
21
34
 
22
35
  it "can construct an object with dependencies" do
@@ -54,6 +67,11 @@ describe "Objection" do
54
67
  @app_module2 = AppModuleII.alloc.init
55
68
  end
56
69
 
70
+ it "has support for eager singletons" do
71
+ @injector = Objection.injector EagerSingletonModule.new
72
+ EagerCar.awoke.should.equal true
73
+ end
74
+
57
75
  it "has support for an injector with a module" do
58
76
  @injector = Objection.injector @app_module
59
77
 
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.3
4
+ version: 0.6.4
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-08 00:00:00.000000000 Z
11
+ date: 2013-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: motion-cocoapods
@@ -40,6 +40,7 @@ files:
40
40
  - Rakefile
41
41
  - app/app_delegate.rb
42
42
  - lib/motion-objection.rb
43
+ - lib/motion-objection/compose.rb
43
44
  - lib/motion-objection/inflector.rb
44
45
  - lib/motion-objection/jsobjection.rb
45
46
  - lib/motion-objection/jsobjection_injector.rb