Sha256: 1065853d187d91f8b640b7cbac4ac56729b29891aa4d67988a53ec17e7f30ff4

Contents?: true

Size: 857 Bytes

Versions: 6

Compression:

Stored size: 857 Bytes

Contents

module ScopedFrom

  module ActiveRecord

    extend ActiveSupport::Concern

    included do |base|
      base.class_attribute(:scope_arities)
      base.scope_arities = ActiveSupport::HashWithIndifferentAccess.new
    end

    module ClassMethods

      def scope(name, scope_options, &block)
        super
        scope_arities[name] = scope_options.is_a?(Proc) ? scope_options.arity : -1
      end

      def scope_with_one_argument?(name)
        scope_arities[name] == 1
      end

      def scope_without_argument?(name)
        scope_arities[name] == 0
      end

      def scoped_from(params, options = {})
        query_class = "#{name}Query".safe_constantize
        query_class = Query unless query_class.is_a?(Class) && query_class.ancestors.include?(Query)
        query_class.new(self, params, options).relation
      end

    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scoped_from-0.9.0 lib/scoped_from/active_record.rb
scoped_from-0.8.5 lib/scoped_from/active_record.rb
scoped_from-0.8.4 lib/scoped_from/active_record.rb
scoped_from-0.8.3 lib/scoped_from/active_record.rb
scoped_from-0.8.2 lib/scoped_from/active_record.rb
scoped_from-0.8.1 lib/scoped_from/active_record.rb