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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77fcd14d6034f8507cd48bcccad8e1c842895bd7
4
- data.tar.gz: fd7c20ee199a1406e6973ef92519617c14cd628a
3
+ metadata.gz: 627a770c9aeffaf9d8eeb4edf178ea2213435793
4
+ data.tar.gz: f69c0af13d7767fb12e33051500cfacfdc58c7e5
5
5
  SHA512:
6
- metadata.gz: 292f9c0256bec186e77be6ca75bb864a6d5b5ea99f1179be7202c6fbe941f4fbe3c4d238f056ad2539f6ed4f12d70f04beb8fce24b9b8616b22b429333447265
7
- data.tar.gz: ce519cfd7d727e6241a745417c74319b84fd47f403a6a92f7e732e954921d69d1fdd106d633c32650564c2c880ec4d36673d1956d3185c29e6698968eca86271
6
+ metadata.gz: 534a3573c278df28a51f29a6575d8701c5532bd27e28afd02f6666a9929fb00ed29fa43989dbd68b29e0282f9e89a3590116f79d31c1cb5f37f37e4ea8d7b5c3
7
+ data.tar.gz: 5a2482c73a63b62f4d5778b6f069af047b26dbd6239a496b35459331ea41a6415ea559010e722ce2ce58aee79053dc679f3299322d6d458d91bd61631c71d7ef
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- octiron (0.3.0)
4
+ octiron (0.4.0)
5
5
  collapsium (~> 0.8)
6
6
  rgl (~> 0.5)
7
7
 
@@ -128,7 +128,10 @@ module Octiron::Transmogrifiers
128
128
 
129
129
  ##
130
130
  # Transmogrify an object of one class into another class.
131
- def transmogrify(from, to)
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 step_to.is_a?(Hash)
162
- result.extend(::Collapsium::PrototypeMatch)
163
- if not result.prototype_match(step_to)
164
- raise "Transmogrifier returned Hash that did not match prototype "\
165
- "#{step_to}, aborting!"
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
@@ -8,5 +8,5 @@
8
8
  #
9
9
  module Octiron
10
10
  # The current release version
11
- VERSION = "0.3.0".freeze
11
+ VERSION = "0.4.0".freeze
12
12
  end
@@ -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, raise_on_nil)
74
+ def initialize(from, verify_results = false)
75
75
  @from = from
76
- @raise_on_nil = raise_on_nil
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
- begin
89
- new_ev = ::Octiron::World.transmogrifier_registry.transmogrify(event, to)
90
- ::Octiron::World.event_bus.publish(new_ev)
91
- rescue RuntimeError
92
- if @raise_on_nil
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
- raise_on_nil = options[:raise_on_nil] || false
112
- return AutoTransmogrifyDelegator.new(from, raise_on_nil)
108
+ verify_results = options[:verify_results] || false
109
+ return AutoTransmogrifyDelegator.new(from, verify_results)
113
110
  end
114
111
 
115
112
  ##
@@ -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, raise_on_nil: true).to Test2 do |_|
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.3.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-15 00:00:00.000000000 Z
11
+ date: 2016-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler