scorpion-ioc 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29856218ea99773e68ec15b55e63f6811455502e
4
- data.tar.gz: 82c22e654b2356a5ebd2a06208488917dc3fef1b
3
+ metadata.gz: 449b0bb3ad037a6a6f8a58240d36fa3dcc435701
4
+ data.tar.gz: 4db64b7b1356846822c8d23359f06c7398cd2cae
5
5
  SHA512:
6
- metadata.gz: ec8b7239dce0671f76b85a4ef257e897d70629a3cbba4728d2936ae6fa48f33894fe6553ca1f385b1d07cd0d502085ca4d5c0e3daf5f60aff3cd7fcdba5791c2
7
- data.tar.gz: 7357980ce557a695e4aa8080e5c5becbc75ced88406a738ef4d25e46597173c2f6dbe682da2fca5a154a079464379c8295846d900cf5e378ac8ff2532330e10d
6
+ metadata.gz: 88dc269d8d2d3308e64c7ea4705bb2e4ba8a17d41fc65b66debff93f801c2d284c47465231363f25c27a68fb24fbf963f8e8860bcbcc6a8348dbda0659810a9f
7
+ data.tar.gz: 2bb0982f0e941f8bce69a050875c4ef52223d00a413faf480cd9cd2d21384abcb22e0d9683e2451ecd87a1d8b962aea89956ae0c8cb34adc675252c6cca8c101
@@ -12,7 +12,7 @@ module Scorpion
12
12
  base.send :include, Scorpion::Object
13
13
  base.send :include, Scorpion::Rails::Nest
14
14
  base.send :around_perform do |job, block|
15
- job.with_scorpion &block
15
+ job.send :with_scorpion, &block
16
16
  end
17
17
 
18
18
  super
@@ -55,12 +55,40 @@ module Scorpion
55
55
  def self.scorpion_nest( &block )
56
56
  nest.prepare &block
57
57
  end
58
+
59
+ # Define dependency resolution that isn't resolved until an instance
60
+ # of a scorpion is conceived to handle an idividual request.
61
+ # @param (see DependencyMap#hunt_for )
62
+ def self.hunt_for( *args, &block )
63
+ instance_hunts << [:hunt_for,args,block]
64
+ end
65
+
66
+ # Define dependency resolution that isn't resolved until an instance
67
+ # of a scorpion is conceived to handle an idividual request.
68
+ # @param (see DependencyMap#capture )
69
+ def self.capture( *args, &block )
70
+ instance_hunts << [:capture,args,block]
71
+ end
72
+
73
+ # Hunting dependencies that cannot be resolved until an instance
74
+ # of the nest class has been created.
75
+ def self.instance_hunts
76
+ @instance_hunts ||= begin
77
+ if superclass.respond_to?( :instance_hunts )
78
+ superclass.instance_hunts.dup
79
+ else
80
+ []
81
+ end
82
+ end
83
+ end
58
84
  end
59
85
  base.nest ||= Scorpion.instance.build_nest
60
86
 
61
87
  super
62
88
  end
63
89
 
90
+ private
91
+
64
92
  # Fetch a scorpion and feed the controller it's dependencies, then yield
65
93
  # to perform the action within the context of that scorpion.
66
94
  def with_scorpion( &block )
@@ -76,11 +104,22 @@ module Scorpion
76
104
  nest.conceive
77
105
  end
78
106
 
107
+ def append_instance_hunts( scorpion )
108
+ scorpion.prepare do |hunter|
109
+ self.class.instance_hunts.each do |method,args,block|
110
+ hunter.send method, *args do |*args|
111
+ instance_exec *args, &block
112
+ end
113
+ end
114
+ end
115
+ end
116
+
79
117
  def ensure_scorpion( existing )
80
118
  scorpion = existing
81
119
  scorpion = assign_scorpion( conceive_scorpion ) unless existing
82
120
 
83
121
  prepare_scorpion( scorpion ) if respond_to?( :prepare_scorpion, true )
122
+ append_instance_hunts( scorpion )
84
123
  scorpion
85
124
  end
86
125
 
@@ -1,5 +1,5 @@
1
1
  module Scorpion
2
- VERSION_NUMBER = "0.5.1"
2
+ VERSION_NUMBER = "0.5.2"
3
3
  VERSION_SUFFIX = ""
4
4
  VERSION = "#{VERSION_NUMBER}#{VERSION_SUFFIX}"
5
5
  end
@@ -5,6 +5,7 @@ module Test
5
5
  class Service; end
6
6
  class Cache; end
7
7
  class Guard; end
8
+ class Provided; end
8
9
  end
9
10
  end
10
11
 
@@ -16,11 +17,25 @@ describe Scorpion::Rails::Controller, type: :controller do
16
17
  cache Test::Nest::Cache
17
18
  end
18
19
 
20
+ hunt_for Test::Nest::Provided do |scorpion|
21
+ scorpion.new Test::Nest::Provided
22
+ end
23
+
24
+ hunt_for String do |scorpion|
25
+ instance_value
26
+ end
27
+
19
28
  def index
20
29
  @guard1 = scorpion.fetch Test::Nest::Guard
21
30
  @guard2 = scorpion.fetch Test::Nest::Guard
22
31
  render nothing: true
23
32
  end
33
+
34
+ private
35
+
36
+ def instance_value
37
+ "Snappy"
38
+ end
24
39
  end
25
40
 
26
41
  context "basics" do
@@ -68,6 +83,14 @@ describe Scorpion::Rails::Controller, type: :controller do
68
83
  expect( subject.cache ).to be_present
69
84
  end
70
85
 
86
+ it "hunts for instance provided dependencies" do
87
+ expect( subject.scorpion.fetch( Test::Nest::Provided ) ).to be_a Test::Nest::Provided
88
+ end
89
+
90
+ it "instance dependencies can access instance methods" do
91
+ expect( subject.scorpion.fetch( String ) ).to eq "Snappy"
92
+ end
93
+
71
94
  it "spawns multiple guards" do
72
95
  expect( assigns( :guard1 ) ).to be_present
73
96
  expect( assigns( :guard2 ) ).to be_present
@@ -130,7 +153,6 @@ describe Scorpion::Rails::Controller, type: :controller do
130
153
  get :index
131
154
  end
132
155
 
133
-
134
156
  it "scopes relations" do
135
157
  allow( subject ).to receive( :index ) do
136
158
  expect( subject.scorpion( Todo ).all.scorpion ).to be subject.scorpion
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorpion-ioc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Alexander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-30 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails