Sha256: bc2c8ee0856f9c0f0b8bafcf8c4d515356d4c345bd30e265197832ed1b8a8791

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

module Scorpion
  module Rails
    module ActiveRecord

      # Make sure that all models return by the relation inherit the relation's
      # scorpion.
      module Relation
        include Scorpion::Stinger

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

        include Scorpion::Method

        #
        # @!endgroup Attributes

        # Elect to use a specific scorpion for all further operations in the
        # chain.
        #
        # @example
        #
        #   User.all.with_scorpion( scorpion ).where( ... )
        #   User.with_scorpion( scorpion ).where( ... )
        def with_scorpion( scorpion )
          spawn.tap do |other|
            other.send :scorpion=, scorpion
          end
        end


        # from ActiveRecord::Relation
        [ :new, :build, :create, :create! ].each do |method|
          class_eval <<-RUBY, __FILE__, __LINE__ + 1
            def #{ method }( *args, &block )
              super *args do |*block_args|
                sting!( block_args )
                yield *block_args if block_given?
              end
            end
          RUBY
        end

        # from ActiveRecord::SpawnMethods
        def spawn
          sting!( super )
        end

        private

          # from ActiveRecord::Relation
          def exec_queries( *args, &block )
            sting!( super )
          end

          # from ActiveRecord::SpawnMethods
          def relation_with( *args )
            sting!( super )
          end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
scorpion-ioc-1.0.10 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.8 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.7 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.6 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.4 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.3 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.2 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.1 lib/scorpion/rails/active_record/relation.rb
scorpion-ioc-1.0.0 lib/scorpion/rails/active_record/relation.rb