Sha256: 36dcc72860ab5c8792c8763d2e19fcfc10580047a6e318d4d7b41d5c3f36436f

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module ActiveRecord
  module NamedScope
    
    class Scope      
      delegate :member_class, :to => :proxy_found      
      include Hobo::Scopes::ApplyScopes      
    end

    module ClassMethods
      def scopes
        hash = read_inheritable_attribute(:scopes)
        if hash.nil?
          if respond_to?(:create_automatic_scope)
            write_inheritable_attribute(:scopes, new_automatic_scoping_hash(self))
          else
            # add a default_proc to optimize the next condition
            write_inheritable_attribute(:scopes, Hash.new { |hash, key| nil })
          end
        elsif hash.default_proc.nil? && respond_to?(:create_automatic_scope)
          write_inheritable_attribute(:scopes, new_automatic_scoping_hash(self).merge!(hash))
        else
          hash
        end
      end
      
      private
      
      def new_automatic_scoping_hash(o)
        hash = Hash.new { |hash, key| o.create_automatic_scope(key) && hash[key] }
        hash.meta_eval do
          define_method :include? do |key, *args|
            super(key, *args) || o.create_automatic_scope(key)
          end
        end
        hash
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hobo-1.1.0 lib/hobo/scopes/named_scope_extensions.rb
hobo-1.1.0.pre4 lib/hobo/scopes/named_scope_extensions.rb
hobo-1.1.0.pre3 lib/hobo/scopes/named_scope_extensions.rb