Sha256: 888ab719c6cbb8de4da8e6e99844bbad7aca0e67f0129ef5ace48bfd2d4222f6

Contents?: true

Size: 1.59 KB

Versions: 26

Compression:

Stored size: 1.59 KB

Contents

module Scorpion
  module Rails
    module ActiveRecord

      # Adds dependency injection to ActiveRecord::Base model associations.
      module Association
        include Scorpion::Stinger

        # ============================================================================
        # @!group Attributes
        #

        include Scorpion::Method

        def scorpion( scope = nil )
          super || owner.scorpion( scope )
        end

        #
        # @!endgroup Attributes


        # Make sure we override the methods of child classes as well.
        def self.prepended( base )
          infect base
          super
        end

        # Propagate the module inheritance to all derived classes so that we can
        # always overlay our interception methods on the top-most overriden
        # method.
        def self.infect( klass )
          klass.class_exec do
            def self.inherited( from )
              Scorpion::Rails::ActiveRecord::Association.infect( from )

              super
            end
          end
          overlay( klass )
        end

        # Overlay interception methods on the klass.
        def self.overlay( klass )
          [ :load_target, :target, :reader, :writer, :scope ].each do |method|
            next unless klass.instance_methods.include? method

            mod = Module.new do
              module_eval <<-EOS, __FILE__, __LINE__ + 1
                def #{ method }( *args, &block )
                  sting! super
                end
              EOS
            end

            klass.prepend mod
          end
        end

      end

    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
scorpion-ioc-0.6.2 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.6.1 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.6.0 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.23 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.22 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.21 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.20 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.19 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.18 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.17 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.16 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.15 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.14 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.13 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.12 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.11 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.10 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.9 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.8 lib/scorpion/rails/active_record/association.rb
scorpion-ioc-0.5.7 lib/scorpion/rails/active_record/association.rb