Sha256: 609374520a6980e299b0ad6e0253e4fdb4bbf8c7eed0b1fef9bf50d58969cbdc

Contents?: true

Size: 854 Bytes

Versions: 6

Compression:

Stored size: 854 Bytes

Contents

module ScopedFrom

  module ActiveRecord

    extend ActiveSupport::Concern

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

    class_methods do

      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-2.0.0 lib/scoped_from/active_record.rb
scoped_from-1.1.1 lib/scoped_from/active_record.rb
scoped_from-1.1.0 lib/scoped_from/active_record.rb
scoped_from-1.0.2 lib/scoped_from/active_record.rb
scoped_from-1.0.1 lib/scoped_from/active_record.rb
scoped_from-1.0.0 lib/scoped_from/active_record.rb