Sha256: 8e512ddadb008b12d61f6af9a5a3e6a7aa6e21fb86f331789ec040a0d2756339

Contents?: true

Size: 876 Bytes

Versions: 1

Compression:

Stored size: 876 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 Rails.version.to_i >= 4
      ActiveRecord::Base.extend(self)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
edge_rider-0.3.0 lib/edge_rider/scoped.rb