Sha256: 779d49514f41ec371c23620b5faec7b2319381b9137986d33623325161765ac2
Contents?: true
Size: 866 Bytes
Versions: 2
Compression:
Stored size: 866 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) [-1, 0].include?(scope_arities[name]) 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).scope end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
scoped_from-0.7.0 | lib/scoped_from/active_record.rb |
scoped_from-0.6.1 | lib/scoped_from/active_record.rb |