Methods
Constants
NON_DELEGATE_METHODS | = | %w(nil? send object_id class extend find size count sum average maximum minimum paginate first last empty? any? respond_to?).to_set |
Attributes
[R] | current_scoped_methods_when_defined | |
[R] | proxy_options | |
[R] | proxy_scope |
Public Class methods
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 114 114: def initialize(proxy_scope, options, &block) 115: options ||= {} 116: [options[:extend]].flatten.each { |extension| extend extension } if options[:extend] 117: extend Module.new(&block) if block_given? 118: unless Scope === proxy_scope 119: @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods) 120: end 121: @proxy_scope, @proxy_options = proxy_scope, options.except(:extend) 122: end
Public Instance methods
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 156 156: def any? 157: if block_given? 158: proxy_found.any? { |*block_args| yield(*block_args) } 159: else 160: !empty? 161: end 162: end
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 148 148: def empty? 149: @found ? @found.empty? : count.zero? 150: end
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 128 128: def first(*args) 129: if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash)) 130: proxy_found.first(*args) 131: else 132: find(:first, *args) 133: end 134: end
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 136 136: def last(*args) 137: if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash)) 138: proxy_found.last(*args) 139: else 140: find(:last, *args) 141: end 142: end
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 124 124: def reload 125: load_found; self 126: end
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 152 152: def respond_to?(method, include_private = false) 153: super || @proxy_scope.respond_to?(method, include_private) 154: end
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 144 144: def size 145: @found ? @found.length : count 146: end
Protected Instance methods
[ show source ]
# File activerecord/lib/active_record/named_scope.rb, line 165 165: def proxy_found 166: @found || load_found 167: end