Fix various issues and add improved test for dependency resolution
This commit is contained in:
@@ -8,9 +8,16 @@ module Laradi
|
||||
|
||||
module Mixin
|
||||
def dependencies(*deps)
|
||||
result = {}
|
||||
deps.each { |dep|
|
||||
include $laradi_injector[dep]
|
||||
instance = $laradi_injector[dep]
|
||||
if instance.nil?
|
||||
raise NoDependencyError, "No dependency found for #{dep}"
|
||||
end
|
||||
result[dep] = instance
|
||||
}
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
9
lib/laradi/exceptions.rb
Normal file
9
lib/laradi/exceptions.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module Laradi
|
||||
|
||||
module Exceptions
|
||||
class NoDependencyError < Exception
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,7 +2,7 @@ class LogicUnitReceiver
|
||||
include Laradi::Mixin
|
||||
|
||||
def get_unit
|
||||
dependencies :logic_unit
|
||||
dependencies(:logic_unit) => {logic_unit:}
|
||||
|
||||
logic_unit
|
||||
end
|
||||
|
||||
@@ -14,7 +14,11 @@ class LaradiTest < ActiveSupport::TestCase
|
||||
test "It can inject dependencies" do
|
||||
lur = LogicUnitReceiver.new
|
||||
|
||||
assert_not_nil lur.get_unit
|
||||
result = lur.get_unit
|
||||
|
||||
assert_not_nil result
|
||||
|
||||
assert_kind_of(LogicUnit, result)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user