| Class | ActiveRecord::NamedScope::Scope |
| In: |
vendor/rails/activerecord/lib/active_record/named_scope.rb
|
| Parent: | Object |
| 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 |
| current_scoped_methods_when_defined | [R] | |
| proxy_options | [R] | |
| proxy_scope | [R] |
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 113
113: def initialize(proxy_scope, options, &block)
114: [options[:extend]].flatten.each { |extension| extend extension } if options[:extend]
115: extend Module.new(&block) if block_given?
116: unless Scope === proxy_scope
117: @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods)
118: end
119: @proxy_scope, @proxy_options = proxy_scope, options.except(:extend)
120: end
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 154
154: def any?
155: if block_given?
156: proxy_found.any? { |*block_args| yield(*block_args) }
157: else
158: !empty?
159: end
160: end
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 146
146: def empty?
147: @found ? @found.empty? : count.zero?
148: end
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 126
126: def first(*args)
127: if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash))
128: proxy_found.first(*args)
129: else
130: find(:first, *args)
131: end
132: end
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 134
134: def last(*args)
135: if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash))
136: proxy_found.last(*args)
137: else
138: find(:last, *args)
139: end
140: end
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 122
122: def reload
123: load_found; self
124: end
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 150
150: def respond_to?(method, include_private = false)
151: super || @proxy_scope.respond_to?(method, include_private)
152: end
# File vendor/rails/activerecord/lib/active_record/named_scope.rb, line 142
142: def size
143: @found ? @found.length : count
144: end