Sha256: 225312ebfc4c24824c3ea40ea39656051d69d1a2eb62d3d20d22c9d8066c0d34

Contents?: true

Size: 1.55 KB

Versions: 26

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 <<-EOS, __FILE__, __LINE__ + 1
            def #{ method }( *args, &block )
              super *args do |*block_args|
                sting!( block_args )
                yield *block_args if block_given?
              end
            end
          EOS
        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

26 entries across 26 versions & 1 rubygems

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