Sha256: 8ff8d05cad5609b2bcf8a25106d728443ac0defd5bc272a1e670c30c83e635c2

Contents?: true

Size: 809 Bytes

Versions: 15

Compression:

Stored size: 809 Bytes

Contents

module Netzke
  module Basepack
    module ActiveRecord
      module RelationExtensions
        def extend_with(*params)
          scope = params.shift
          case scope
          when Symbol # model's scope
            self.send(scope, *params)
          when String # SQL query or SQL query with params (e.g. ["created_at < ?", 1.day.ago])
            params.empty? ? self.where(scope) : self.where([scope, *params])
          when Array
            self.extend_with(*scope)
          when Hash  # conditions hash
            self.where(scope)
          when Proc  # receives a relation, must return a relation
            scope.call(self)
          else
            raise ArgumentError, "Wrong parameter type for ActiveRecord::Relation#extend_with"
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
netzke-basepack-0.12.8 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.7 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.6 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.5 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.4 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.3 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.2 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.1 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.11.2 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.11.1 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.0 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.0.rc1 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.12.0.beta lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.11.0 lib/netzke/basepack/active_record/relation_extensions.rb
netzke-basepack-0.10.1 lib/netzke/basepack/active_record/relation_extensions.rb