scorpion-ioc 0.3.1 → 0.4.0
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/.gitignore +2 -1
- data/.rspec +2 -1
- data/README.md +111 -44
- data/lib/scorpion/attribute.rb +0 -1
- data/lib/scorpion/attribute_set.rb +15 -7
- data/lib/scorpion/dependency/argument_dependency.rb +25 -0
- data/lib/scorpion/{prey/builder_prey.rb → dependency/builder_dependency.rb} +8 -8
- data/lib/scorpion/dependency/captured_dependency.rb +44 -0
- data/lib/scorpion/dependency/class_dependency.rb +25 -0
- data/lib/scorpion/dependency/module_dependency.rb +14 -0
- data/lib/scorpion/dependency.rb +137 -0
- data/lib/scorpion/dependency_map.rb +135 -0
- data/lib/scorpion/hunt.rb +158 -0
- data/lib/scorpion/hunter.rb +21 -20
- data/lib/scorpion/locale/en.yml +5 -1
- data/lib/scorpion/{king.rb → object.rb} +72 -53
- data/lib/scorpion/object_constructor.rb +55 -0
- data/lib/scorpion/rails/active_record/association.rb +65 -0
- data/lib/scorpion/rails/active_record/model.rb +28 -0
- data/lib/scorpion/rails/active_record/relation.rb +66 -0
- data/lib/scorpion/rails/active_record.rb +21 -0
- data/lib/scorpion/rails/controller.rb +22 -62
- data/lib/scorpion/rails/job.rb +30 -0
- data/lib/scorpion/rails/nest.rb +86 -0
- data/lib/scorpion/rails/railtie.rb +16 -0
- data/lib/scorpion/rails.rb +4 -0
- data/lib/scorpion/rspec/helper.rb +25 -0
- data/lib/scorpion/rspec.rb +17 -0
- data/lib/scorpion/stinger.rb +69 -0
- data/lib/scorpion/version.rb +1 -1
- data/lib/scorpion.rb +91 -44
- data/scorpion.gemspec +1 -1
- data/spec/internal/app/models/author.rb +17 -0
- data/spec/internal/app/models/todo.rb +14 -0
- data/spec/internal/db/schema.rb +12 -1
- data/spec/lib/scorpion/dependency/argument_dependency_spec.rb +18 -0
- data/spec/lib/scorpion/dependency/builder_dependency_spec.rb +41 -0
- data/spec/lib/scorpion/dependency/module_dependency_spec.rb +16 -0
- data/spec/lib/scorpion/dependency_map_spec.rb +108 -0
- data/spec/lib/scorpion/dependency_spec.rb +131 -0
- data/spec/lib/scorpion/hunt_spec.rb +93 -0
- data/spec/lib/scorpion/hunter_spec.rb +53 -14
- data/spec/lib/scorpion/object_constructor_spec.rb +49 -0
- data/spec/lib/scorpion/object_spec.rb +214 -0
- data/spec/lib/scorpion/rails/active_record/association_spec.rb +26 -0
- data/spec/lib/scorpion/rails/active_record/model_spec.rb +33 -0
- data/spec/lib/scorpion/rails/active_record/relation_spec.rb +72 -0
- data/spec/lib/scorpion/rails/controller_spec.rb +9 -9
- data/spec/lib/scorpion/rails/job_spec.rb +34 -0
- data/spec/lib/scorpion/rspec/helper_spec.rb +44 -0
- data/spec/lib/scorpion_spec.rb +0 -35
- data/spec/spec_helper.rb +1 -0
- metadata +54 -26
- data/lib/scorpion/hunting_map.rb +0 -139
- data/lib/scorpion/prey/captured_prey.rb +0 -44
- data/lib/scorpion/prey/class_prey.rb +0 -13
- data/lib/scorpion/prey/hunted_prey.rb +0 -14
- data/lib/scorpion/prey/module_prey.rb +0 -14
- data/lib/scorpion/prey.rb +0 -94
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/lib/scorpion/hunting_map_spec.rb +0 -126
- data/spec/lib/scorpion/instance_spec.rb +0 -5
- data/spec/lib/scorpion/king_spec.rb +0 -198
- data/spec/lib/scorpion/prey/builder_prey_spec.rb +0 -42
- data/spec/lib/scorpion/prey/module_prey_spec.rb +0 -16
- data/spec/lib/scorpion/prey_spec.rb +0 -76
@@ -1,198 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Test
|
4
|
-
module King
|
5
|
-
class UserService; end
|
6
|
-
class Logger; end
|
7
|
-
class BackLogger; end
|
8
|
-
class ColorLogger; end
|
9
|
-
|
10
|
-
class Mamal
|
11
|
-
include Scorpion::King
|
12
|
-
|
13
|
-
def initialize( family, parent = nil, options={}, &block )
|
14
|
-
@family = family
|
15
|
-
@parent = parent
|
16
|
-
@options = feast_on! options
|
17
|
-
|
18
|
-
|
19
|
-
yield if block_given?
|
20
|
-
end
|
21
|
-
|
22
|
-
feed_on do
|
23
|
-
user_service Test::King::UserService
|
24
|
-
logger Test::King::Logger
|
25
|
-
manager Test::King::Logger, public: true
|
26
|
-
executive_manager Test::King::Logger, private: true
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_accessor :family
|
30
|
-
attr_accessor :parent
|
31
|
-
attr_accessor :options
|
32
|
-
end
|
33
|
-
|
34
|
-
class Mouse < Mamal
|
35
|
-
|
36
|
-
feed_on do
|
37
|
-
cheese Test::King::Logger
|
38
|
-
logger Test::King::BackLogger
|
39
|
-
end
|
40
|
-
def initialize( options = {} )
|
41
|
-
super 'mouse', nil, options
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Bear < Mamal
|
46
|
-
feed_on do
|
47
|
-
logger Test::King::ColorLogger
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe Scorpion::King do
|
55
|
-
|
56
|
-
let( :scorpion ){ double Scorpion }
|
57
|
-
|
58
|
-
before( :each ) do
|
59
|
-
allow( scorpion ).to receive( :feed )
|
60
|
-
end
|
61
|
-
|
62
|
-
describe ".spawn" do
|
63
|
-
|
64
|
-
it "can spawn" do
|
65
|
-
mamal = Test::King::Mamal.spawn scorpion, 'mouse', 'rodent', name: 'name'
|
66
|
-
expect( mamal ).to be_a Test::King::Mamal
|
67
|
-
end
|
68
|
-
|
69
|
-
it "calls feed" do
|
70
|
-
expect( scorpion ).to receive( :feed )
|
71
|
-
Test::King::Mouse.spawn scorpion
|
72
|
-
end
|
73
|
-
|
74
|
-
it "can inherit" do
|
75
|
-
mouse = Test::King::Mouse.spawn scorpion, name: 'name'
|
76
|
-
expect( mouse.family ).to eq 'mouse'
|
77
|
-
expect( mouse.options ).to include name: 'name'
|
78
|
-
end
|
79
|
-
|
80
|
-
it "yields to constructor" do
|
81
|
-
expect do |b|
|
82
|
-
Test::King::Mouse.spawn scorpion, name: 'name', &b
|
83
|
-
end.to yield_control
|
84
|
-
end
|
85
|
-
|
86
|
-
it "invokes on_fed" do
|
87
|
-
expect_any_instance_of( Test::King::Mouse ).to receive( :on_fed )
|
88
|
-
Test::King::Mouse.spawn scorpion
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "accessors" do
|
93
|
-
let( :king ) do
|
94
|
-
Test::King::Mamal.spawn scorpion, 'harry', 'jim', name: 'name', manager: double
|
95
|
-
end
|
96
|
-
|
97
|
-
subject{ king }
|
98
|
-
|
99
|
-
it "defines accessors" do
|
100
|
-
expect( king ).to respond_to :user_service
|
101
|
-
expect( king ).not_to respond_to :user_service=
|
102
|
-
end
|
103
|
-
|
104
|
-
it "supports private reader" do
|
105
|
-
expect( king.respond_to? :executive_manager, false ).to be_falsy
|
106
|
-
expect( king.respond_to? :executive_manager, true ).to be_truthy
|
107
|
-
end
|
108
|
-
|
109
|
-
it "supports public writer" do
|
110
|
-
expect( king.respond_to? :manager=, false ).to be_truthy
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "inheritance" do
|
114
|
-
let( :king ) do
|
115
|
-
Test::King::Mouse.spawn scorpion
|
116
|
-
end
|
117
|
-
|
118
|
-
it "inherits attributes" do
|
119
|
-
expect( king.injected_attributes[:user_service].contract ).to be Test::King::UserService
|
120
|
-
end
|
121
|
-
|
122
|
-
it "overrides attributes" do
|
123
|
-
expect( king.injected_attributes[:logger].contract ).to be Test::King::BackLogger
|
124
|
-
end
|
125
|
-
|
126
|
-
it "doesn't effect other classes" do
|
127
|
-
expect( Test::King::Bear.spawn( scorpion, 'Yogi' ).injected_attributes[:logger].contract ).to be Test::King::ColorLogger
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "feasting" do
|
135
|
-
let( :logger ) { Test::King::Logger.new }
|
136
|
-
let( :options ) { { manager: logger, color: :red } }
|
137
|
-
let( :king ) { Test::King::Mouse.new name: 'mighty' }
|
138
|
-
|
139
|
-
|
140
|
-
describe "#feast_on" do
|
141
|
-
it "assigns attributes" do
|
142
|
-
king.send :feast_on, options
|
143
|
-
expect( king.manager ).to be logger
|
144
|
-
end
|
145
|
-
|
146
|
-
it "doesn't overwrite" do
|
147
|
-
king.manager = Test::King::Logger.new
|
148
|
-
king.send :feast_on, options
|
149
|
-
expect( king.manager ).not_to be logger
|
150
|
-
end
|
151
|
-
|
152
|
-
it "overwrites when asked" do
|
153
|
-
king.manager = Test::King::Logger.new
|
154
|
-
king.send :feast_on, options, true
|
155
|
-
expect( king.manager ).to be logger
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "feast_on!" do
|
160
|
-
it "assigns attributes" do
|
161
|
-
king.send :feast_on!, options
|
162
|
-
expect( king.manager ).to be logger
|
163
|
-
end
|
164
|
-
|
165
|
-
it "doesn't overwrite" do
|
166
|
-
king.manager = Test::King::Logger.new
|
167
|
-
king.send :feast_on!, options
|
168
|
-
expect( king.manager ).not_to be logger
|
169
|
-
end
|
170
|
-
|
171
|
-
it "overwrites when asked" do
|
172
|
-
king.manager = Test::King::Logger.new
|
173
|
-
king.send :feast_on!, options, true
|
174
|
-
expect( king.manager ).to be logger
|
175
|
-
end
|
176
|
-
|
177
|
-
it "removes injected attributes" do
|
178
|
-
expect( options ).to have_key :manager
|
179
|
-
king.send :feast_on!, options
|
180
|
-
expect( options ).not_to have_key :manager
|
181
|
-
end
|
182
|
-
|
183
|
-
it "removes injected attribute even if already set" do
|
184
|
-
expect( options ).to have_key :manager
|
185
|
-
king.manager = Test::King::Logger.new
|
186
|
-
king.send :feast_on!, options
|
187
|
-
expect( options ).not_to have_key :manager
|
188
|
-
end
|
189
|
-
|
190
|
-
it "doesn't remove other options" do
|
191
|
-
king.send :feast_on!, options
|
192
|
-
expect( options ).to have_key :color
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Test
|
4
|
-
module BuilderPrey
|
5
|
-
class ClassDelegate
|
6
|
-
def call( scorpion, *args, &block )
|
7
|
-
Test
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module ModDelegate
|
12
|
-
module_function
|
13
|
-
|
14
|
-
def call( scorpion, *args, &block )
|
15
|
-
Test
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe Scorpion::Prey::BuilderPrey do
|
22
|
-
let( :scorpion ){ double }
|
23
|
-
|
24
|
-
it "supports class hunting delegates" do
|
25
|
-
prey = Scorpion::Prey::BuilderPrey.new( String, nil, Test::BuilderPrey::ClassDelegate.new )
|
26
|
-
expect( prey.fetch( scorpion ) ).to be Test
|
27
|
-
end
|
28
|
-
|
29
|
-
it "supports module hunting delegates" do
|
30
|
-
prey = Scorpion::Prey::BuilderPrey.new( String, nil, Test::BuilderPrey::ModDelegate )
|
31
|
-
expect( prey.fetch( scorpion ) ).to be Test
|
32
|
-
end
|
33
|
-
|
34
|
-
it "supports block hunting delegates" do
|
35
|
-
prey = Scorpion::Prey::BuilderPrey.new( String, nil ) do
|
36
|
-
Test
|
37
|
-
end
|
38
|
-
expect( prey.fetch( scorpion ) ).to be Test
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Test
|
4
|
-
module ModulePrey
|
5
|
-
module Example; end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
describe Scorpion::Prey::ModulePrey do
|
9
|
-
let( :scorpion ){ double }
|
10
|
-
let( :prey ) { Scorpion::Prey::ModulePrey.new( Test::ModulePrey::Example ) }
|
11
|
-
|
12
|
-
it "returns the module itself" do
|
13
|
-
expect( prey.fetch( scorpion ) ).to be Test::ModulePrey::Example
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Test
|
4
|
-
module Prey
|
5
|
-
module Mod; end
|
6
|
-
class Base; end
|
7
|
-
class Derived < Base
|
8
|
-
include Mod
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Scorpion::Prey do
|
14
|
-
context "inheritance" do
|
15
|
-
let( :prey ){ Scorpion::Prey.new( Test::Prey::Derived ) }
|
16
|
-
|
17
|
-
it "matches more derived class when looking for base class" do
|
18
|
-
expect( prey.satisfies? Test::Prey::Base ).to be_truthy
|
19
|
-
end
|
20
|
-
|
21
|
-
it "matches same class when looking for base class" do
|
22
|
-
expect( prey.satisfies? Test::Prey::Derived ).to be_truthy
|
23
|
-
end
|
24
|
-
|
25
|
-
it "does not inherit symbols" do
|
26
|
-
expect( Scorpion::Prey.new( :a ).satisfies? :b ).to be_falsy
|
27
|
-
end
|
28
|
-
|
29
|
-
it "can satisfy a module with a class" do
|
30
|
-
expect( prey.satisfies? Test::Prey::Mod ).to be_truthy
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "traits" do
|
36
|
-
|
37
|
-
context "symbolic" do
|
38
|
-
let( :prey ){ Scorpion::Prey.new Test::Prey::Base, :apples }
|
39
|
-
it "satisfies matched traits" do
|
40
|
-
expect( prey.satisfies? Test::Prey::Base, :apples ).to be_truthy
|
41
|
-
end
|
42
|
-
|
43
|
-
it "doesn't satisfy mis-matched traits" do
|
44
|
-
expect( prey.satisfies? Test::Prey::Base, :oranges ).to be_falsy
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "module" do
|
49
|
-
let( :prey ){ Scorpion::Prey.new Test::Prey::Derived }
|
50
|
-
|
51
|
-
it "satisfies module traits" do
|
52
|
-
expect( prey.satisfies? Test::Prey::Base, Test::Prey::Derived ).to be_truthy
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
it "can satisfy symbol contracts" do
|
59
|
-
expect( Scorpion::Prey.new( :symbol ).satisfies? :symbol ).to be_truthy
|
60
|
-
end
|
61
|
-
|
62
|
-
it "satisfies ignores tail hash traits" do
|
63
|
-
expect( Scorpion::Prey.new( Test::Prey::Base ).satisfies?( Test::Prey::Base, ) )
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "equality" do
|
67
|
-
let( :prey ) { Scorpion::Prey.new( Test::Prey::Derived ) }
|
68
|
-
let( :same ) { Scorpion::Prey.new( Test::Prey::Derived ) }
|
69
|
-
let( :different ) { Scorpion::Prey.new( Test::Prey::Base ) }
|
70
|
-
|
71
|
-
specify{ expect( prey ).to eq same }
|
72
|
-
specify{ expect( prey ).not_to eq different }
|
73
|
-
specify{ expect( prey.hash ).to eq same.hash }
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|