scorpion-ioc 0.5.1 → 0.5.2
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 +4 -4
- data/lib/scorpion/rails/job.rb +1 -1
- data/lib/scorpion/rails/nest.rb +39 -0
- data/lib/scorpion/version.rb +1 -1
- data/spec/lib/scorpion/rails/controller_spec.rb +23 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 449b0bb3ad037a6a6f8a58240d36fa3dcc435701
|
4
|
+
data.tar.gz: 4db64b7b1356846822c8d23359f06c7398cd2cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88dc269d8d2d3308e64c7ea4705bb2e4ba8a17d41fc65b66debff93f801c2d284c47465231363f25c27a68fb24fbf963f8e8860bcbcc6a8348dbda0659810a9f
|
7
|
+
data.tar.gz: 2bb0982f0e941f8bce69a050875c4ef52223d00a413faf480cd9cd2d21384abcb22e0d9683e2451ecd87a1d8b962aea89956ae0c8cb34adc675252c6cca8c101
|
data/lib/scorpion/rails/job.rb
CHANGED
data/lib/scorpion/rails/nest.rb
CHANGED
@@ -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
|
|
data/lib/scorpion/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|