scorpion-ioc 0.5.20 → 0.5.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scorpion/error.rb +10 -0
- data/lib/scorpion/locale/en.yml +1 -0
- data/lib/scorpion/object.rb +13 -2
- data/lib/scorpion/version.rb +1 -1
- data/spec/lib/scorpion/object_constructor_spec.rb +18 -0
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e4554b3de6ac16dd3564b7ce94776dbe389ecce
|
4
|
+
data.tar.gz: 32245b81b11860337171ae2df0b867f7bd0758f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b73bd3f9581b6a626d3dd07b4cbafdea26bc938f7f22d1cb4d2cdbcba361ff6b6c529f6fc4c9a0d8b39029735e7782779dd5bb0d15d72a8ee175eedda076c82
|
7
|
+
data.tar.gz: 49b1a70c443588a55f28165bcf89e23fc427b635f257f41233700b56bd3af8166e504f7e80c0d3561830706b1815f0f54d3e0d5c5accc69b9e45e2bd3aeb832e
|
data/lib/scorpion/error.rb
CHANGED
@@ -32,4 +32,14 @@ module Scorpion
|
|
32
32
|
super ( message || translate( :builder_required ) )
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
class ContractMismatchError < Error
|
37
|
+
def initialize( message_or_module = nil, initializer_attr = nil, injected_attr = nil )
|
38
|
+
if message_or_module.is_a?( Module )
|
39
|
+
super translate( :contract_mismatch, module: message_or_module, name: initializer_attr.name, from: initializer_attr.contract, to: injected_attr.contract )
|
40
|
+
else
|
41
|
+
super ( message || translate( :contract_mismatch ) )
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
35
45
|
end
|
data/lib/scorpion/locale/en.yml
CHANGED
@@ -6,6 +6,7 @@ en:
|
|
6
6
|
builder_required: A custom builder must be provided to resolve this dependency
|
7
7
|
arity_mismatch: The block must accept %{expected} arguments, but actually expects %{actual}
|
8
8
|
rack_missing_scorpion: Scorpion not set. Add Scorpion::Rack::Middleware before %{middleware}.
|
9
|
+
contract_mismatch: "%{module} changed the contract for `%{name}` from `%{from}` to `%{to}` but did not update `initialize` block."
|
9
10
|
warnings:
|
10
11
|
messages:
|
11
12
|
mixed_scorpions: A scorpion has already been assigned. Mixing scorpions can result in unexpected results.
|
data/lib/scorpion/object.rb
CHANGED
@@ -131,6 +131,7 @@ module Scorpion
|
|
131
131
|
Scorpion::ObjectConstructor.new( self, arguments ).define if arguments.present?
|
132
132
|
injected_attributes.define &block
|
133
133
|
build_injected_attributes
|
134
|
+
validate_initializer_injections
|
134
135
|
end
|
135
136
|
|
136
137
|
# Define a single dependency and accessor.
|
@@ -141,10 +142,12 @@ module Scorpion
|
|
141
142
|
attr = injected_attributes.define_attribute name, contract, *traits, &block
|
142
143
|
build_injected_attribute attr
|
143
144
|
set_injected_attribute_visibility attr
|
145
|
+
validate_initializer_injections
|
146
|
+
attr
|
144
147
|
end
|
145
148
|
|
146
149
|
# @!attribute
|
147
|
-
# @return [Scorpion::AttributeSet] the set of injected
|
150
|
+
# @return [Scorpion::AttributeSet] the set of injected attributes.
|
148
151
|
def injected_attributes
|
149
152
|
@injected_attributes ||= begin
|
150
153
|
attrs = AttributeSet.new
|
@@ -154,7 +157,7 @@ module Scorpion
|
|
154
157
|
end
|
155
158
|
|
156
159
|
# @!attribute
|
157
|
-
# @return [Scorpion::AttributeSet] the set of injected
|
160
|
+
# @return [Scorpion::AttributeSet] the set of injected attributes.
|
158
161
|
def initializer_injections
|
159
162
|
@initializer_injections ||= begin
|
160
163
|
if superclass.respond_to?( :initializer_injections )
|
@@ -166,6 +169,14 @@ module Scorpion
|
|
166
169
|
end
|
167
170
|
|
168
171
|
private
|
172
|
+
def validate_initializer_injections
|
173
|
+
initializer_injections.each do |attr|
|
174
|
+
injected = injected_attributes[ attr.name ]
|
175
|
+
if injected.contract != attr.contract
|
176
|
+
fail Scorpion::ContractMismatchError.new( self, attr, injected )
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
169
180
|
|
170
181
|
def build_injected_attributes
|
171
182
|
injected_attributes.each do |attr|
|
data/lib/scorpion/version.rb
CHANGED
@@ -101,6 +101,24 @@ describe Scorpion::ObjectConstructor do
|
|
101
101
|
expect( more_derived.initializer_injections.count ).to eq 0
|
102
102
|
end
|
103
103
|
|
104
|
+
it "fails if changing attribute without changing initializer" do
|
105
|
+
expect do
|
106
|
+
overriden = Class.new( klass ) do
|
107
|
+
attr_dependency :label, Integer
|
108
|
+
end
|
109
|
+
end.to raise_exception Scorpion::ContractMismatchError
|
110
|
+
end
|
111
|
+
|
112
|
+
it "works if changing attribute and changing initializer" do
|
113
|
+
expect do
|
114
|
+
overriden = Class.new( klass ) do
|
115
|
+
|
116
|
+
initialize label: Integer
|
117
|
+
attr_dependency :label, Integer
|
118
|
+
end
|
119
|
+
end.not_to raise_exception
|
120
|
+
end
|
121
|
+
|
104
122
|
end
|
105
123
|
|
106
124
|
end
|
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.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Alexander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -256,4 +256,3 @@ test_files:
|
|
256
256
|
- spec/lib/scorpion/rspec/helper_spec.rb
|
257
257
|
- spec/lib/scorpion_spec.rb
|
258
258
|
- spec/spec_helper.rb
|
259
|
-
has_rdoc:
|