Sha256: 6d98132fb6beee75ab8da9169f10ba65dd2ac4fcc0c65c8de22a8dc03f2e3976
Contents?: true
Size: 886 Bytes
Versions: 3
Compression:
Stored size: 886 Bytes
Contents
module EdgeRider module Scoped VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock ] def scoped(options = nil) options ||= {} relation = all options.assert_valid_keys(VALID_FIND_OPTIONS) finders = options.dup finders.delete_if { |key, value| value.nil? && key != :limit } ((VALID_FIND_OPTIONS - [:conditions, :include]) & finders.keys).each do |finder| relation = relation.send(finder, finders[finder]) end relation = relation.where(finders[:conditions]) if options.has_key?(:conditions) relation = relation.includes(finders[:include]) if options.has_key?(:include) relation end if ActiveRecord::VERSION::MAJOR >= 4 ActiveRecord::Base.extend(self) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
edge_rider-0.3.3 | lib/edge_rider/scoped.rb |
edge_rider-0.3.2 | lib/edge_rider/scoped.rb |
edge_rider-0.3.1 | lib/edge_rider/scoped.rb |