Module: Hypo::ScopeFriendly
Instance Method Summary collapse
- #bind_to(scope) ⇒ Object (also: #bound_to)
- #scope ⇒ Object
Instance Method Details
#bind_to(scope) ⇒ Object Also known as: bound_to
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/hypo/scope_friendly.rb', line 3 def bind_to(scope) if scope.is_a? Symbol @scope_name = scope else @scope = scope @scope.instance_variable_set('@instances'.freeze, Hash.new) end self end |
#scope ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/hypo/scope_friendly.rb', line 14 def scope if @scope.nil? && @scope_name.nil? raise ContainerError, "Component \"#{@name}\" must be bound to a scope" \ " according to Hypo::Lifetime::Scope lifetime strategy" end @scope || @container.resolve(@scope_name) end |