octiron 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/octiron/transmogrifiers/registry.rb +18 -9
- data/lib/octiron/version.rb +1 -1
- data/lib/octiron/world.rb +9 -12
- data/spec/world_spec.rb +1 -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: 627a770c9aeffaf9d8eeb4edf178ea2213435793
|
4
|
+
data.tar.gz: f69c0af13d7767fb12e33051500cfacfdc58c7e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 534a3573c278df28a51f29a6575d8701c5532bd27e28afd02f6666a9929fb00ed29fa43989dbd68b29e0282f9e89a3590116f79d31c1cb5f37f37e4ea8d7b5c3
|
7
|
+
data.tar.gz: 5a2482c73a63b62f4d5778b6f069af047b26dbd6239a496b35459331ea41a6415ea559010e722ce2ce58aee79053dc679f3299322d6d458d91bd61631c71d7ef
|
data/Gemfile.lock
CHANGED
@@ -128,7 +128,10 @@ module Octiron::Transmogrifiers
|
|
128
128
|
|
129
129
|
##
|
130
130
|
# Transmogrify an object of one class into another class.
|
131
|
-
|
131
|
+
# If `verify_results` is true, the transmogrification result is checked
|
132
|
+
# to match the target class or hash, and an error is raised if there is no
|
133
|
+
# match.
|
134
|
+
def transmogrify(from, to, verify_results = true)
|
132
135
|
# Get lookup keys
|
133
136
|
from_name = from.class.to_s
|
134
137
|
if from.is_a?(Hash)
|
@@ -158,15 +161,21 @@ module Octiron::Transmogrifiers
|
|
158
161
|
result = @transmogrifiers[key].call(input)
|
159
162
|
|
160
163
|
# Verify result
|
161
|
-
if
|
162
|
-
result.
|
163
|
-
|
164
|
-
|
165
|
-
|
164
|
+
if verify_results
|
165
|
+
if result.nil?
|
166
|
+
raise "Transmogrifier returned nil result!"
|
167
|
+
end
|
168
|
+
|
169
|
+
if step_to.is_a?(Hash)
|
170
|
+
result.extend(::Collapsium::PrototypeMatch)
|
171
|
+
if not result.prototype_match(step_to)
|
172
|
+
raise "Transmogrifier returned Hash that did not match prototype "\
|
173
|
+
"#{step_to}, aborting!"
|
174
|
+
end
|
175
|
+
elsif result.class.to_s != step_to
|
176
|
+
raise "Transmogrifier returned result of invalid class "\
|
177
|
+
"#{result.class}, aborting!"
|
166
178
|
end
|
167
|
-
elsif result.class.to_s != step_to
|
168
|
-
raise "Transmogrifier returned result of invalid class "\
|
169
|
-
"#{result.class}, aborting!"
|
170
179
|
end
|
171
180
|
|
172
181
|
# Result is input for the next transmogrifier in the chain
|
data/lib/octiron/version.rb
CHANGED
data/lib/octiron/world.rb
CHANGED
@@ -71,9 +71,9 @@ module Octiron::World
|
|
71
71
|
# Delegator for the autotransmogiry(FROM).to TO syntax
|
72
72
|
# @api private
|
73
73
|
class AutoTransmogrifyDelegator < TransmogrifierRegistrator
|
74
|
-
def initialize(from,
|
74
|
+
def initialize(from, verify_results = false)
|
75
75
|
@from = from
|
76
|
-
@
|
76
|
+
@verify_results = verify_results
|
77
77
|
end
|
78
78
|
|
79
79
|
def to(to, transmogrifier_object = nil, &transmogrifier_proc)
|
@@ -85,14 +85,11 @@ module Octiron::World
|
|
85
85
|
::Octiron::World.event_bus.subscribe(@from) do |event|
|
86
86
|
# By default, we don't want to raise errors if the transmogrifier
|
87
87
|
# returns nil. Still, raising should be activated optionally.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
raise
|
94
|
-
end
|
95
|
-
end
|
88
|
+
new_ev = ::Octiron::World.transmogrifier_registry.transmogrify(
|
89
|
+
event, to,
|
90
|
+
@verify_results
|
91
|
+
)
|
92
|
+
::Octiron::World.event_bus.publish(new_ev)
|
96
93
|
end
|
97
94
|
end
|
98
95
|
end
|
@@ -108,8 +105,8 @@ module Octiron::World
|
|
108
105
|
# By default, a transmogrifier that returns a nil object simply does not
|
109
106
|
# publish a result.
|
110
107
|
def autotransmogrify(from, options = {})
|
111
|
-
|
112
|
-
return AutoTransmogrifyDelegator.new(from,
|
108
|
+
verify_results = options[:verify_results] || false
|
109
|
+
return AutoTransmogrifyDelegator.new(from, verify_results)
|
113
110
|
end
|
114
111
|
|
115
112
|
##
|
data/spec/world_spec.rb
CHANGED
@@ -89,7 +89,7 @@ describe Octiron::World do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it "can raise on nil transmogrification results" do
|
92
|
-
@tester.autotransmogrify(Test1,
|
92
|
+
@tester.autotransmogrify(Test1, verify_results: true).to Test2 do |_|
|
93
93
|
# Nothing happening here
|
94
94
|
end
|
95
95
|
expect { @tester.publish(Test1.new) }.to raise_error(RuntimeError)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octiron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Finkhaeuser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|