Module: Scorpion::Stinger
- Included in:
- Rails::ActiveRecord::Association, Rails::ActiveRecord::Model, Rails::ActiveRecord::Relation
- Defined in:
- lib/scorpion/stinger.rb
Overview
Utility methods for propagating a Scorpion to returned objects.
Class Method Summary collapse
Instance Method Summary collapse
-
#sting!(object) ⇒ object
Sting an object so that it will be injected with the scorpion and use it to resolve all dependencies.
Class Method Details
.wrap(instance, stinger) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/scorpion/stinger.rb', line 6 def self.wrap( instance, stinger ) return instance unless instance klass = @wrappers[instance.class] ||= Class.new( instance.class ) do def initialize( instance, stinger ) @__instance__ = instance @__stinger__ = stinger end def respond_to?( *args ) @__instance__.respond_to?( *args ) end private def method_missing( *args, &block ) # rubocop:disable Style/MethodMissingSuper @__stinger__.sting! @__instance__.__send__( *args, &block ) end end klass.new instance, stinger end |
Instance Method Details
#sting!(object) ⇒ object
Sting an object so that it will be injected with the scorpion and use it to resolve all dependencies.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scorpion/stinger.rb', line 34 def sting!( object ) return object unless scorpion if object assign_scorpion object assign_scorpion_to_enumerable object end object end |