Class: WillPaginate::NamedScope::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/will_paginate/named_scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy_scope, options) ⇒ Scope

Returns a new instance of Scope.



115
116
117
118
119
# File 'lib/will_paginate/named_scope.rb', line 115

def initialize(proxy_scope, options)
  [options[:extend]].flatten.each { |extension| extend extension } if options[:extend]
  extend Module.new { |*args| yield(*args) } if block_given?
  @proxy_scope, @proxy_options = proxy_scope, options.except(:extend)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



155
156
157
158
159
160
161
162
163
# File 'lib/will_paginate/named_scope.rb', line 155

def method_missing(method, *args)
  if scopes.include?(method)
    scopes[method].call(self, *args)
  else
    with_scope :find => proxy_options do
      proxy_scope.send(method, *args) { |*a| yield(*a) if block_given? }
    end
  end
end

Instance Attribute Details

#proxy_optionsObject (readonly)

Returns the value of attribute proxy_options.



105
106
107
# File 'lib/will_paginate/named_scope.rb', line 105

def proxy_options
  @proxy_options
end

#proxy_scopeObject (readonly)

Returns the value of attribute proxy_scope.



105
106
107
# File 'lib/will_paginate/named_scope.rb', line 105

def proxy_scope
  @proxy_scope
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/will_paginate/named_scope.rb', line 141

def empty?
  @found ? @found.empty? : count.zero?
end

#first(*args) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/will_paginate/named_scope.rb', line 125

def first(*args)
  if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash))
    proxy_found.first(*args)
  else
    find(:first, *args)
  end
end

#last(*args) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/will_paginate/named_scope.rb', line 133

def last(*args)
  if args.first.kind_of?(Integer) || (@found && !args.first.kind_of?(Hash))
    proxy_found.last(*args)
  else
    find(:last, *args)
  end
end

#reloadObject



121
122
123
# File 'lib/will_paginate/named_scope.rb', line 121

def reload
  load_found; self
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/will_paginate/named_scope.rb', line 145

def respond_to?(method, include_private = false)
  super || @proxy_scope.respond_to?(method, include_private)
end