lib/mediator/registry.rb in mediator-0.4.1 vs lib/mediator/registry.rb in mediator-0.4.2
- old
+ new
@@ -1,6 +1,7 @@
require "mediator/errors"
+require "ostruct"
class Mediator
module Registry
# Sugar for `register`.
@@ -29,9 +30,14 @@
# Options:
# context - passed to new context
# registry - optional registry map to use instead of default
def for subject, opts = {}
+ # Return a dummy mediator is subject is nil
+ # (can happen with r.one :foo, empty: true)
+
+ return OpenStruct.new render: nil if subject == nil
+
context = opts[:context]
reg = registry(opts[:registry] || context)
reg.keys.reverse.each do |criteria|