# File lib/will_paginate/core_ext.rb, line 49 def constantize unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self raise NameError, "#{self.inspect} is not a valid constant name!" end Object.module_eval("::#{$1}", __FILE__, __LINE__) end
Returns a new hash without the given keys.
# File lib/will_paginate/core_ext.rb, line 20 def except(*keys) rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) reject { |key,| rejected.include?(key) } end
Replaces the hash without only the given keys.
# File lib/will_paginate/core_ext.rb, line 26 def except!(*keys) replace(except(*keys)) end
# File lib/will_paginate/finders/active_record/named_scope_patch.rb, line 28 def method_missing(method, *args, &block) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) super elsif @reflection.klass.scopes.include?(method) @reflection.klass.scopes[method].call(self, *args) else @reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do @reflection.klass.send(method, *args, &block) end end end
# File lib/will_paginate/finders/active_record/named_scope_patch.rb, line 15 def method_missing_without_paginate(method, *args, &block) if @reflection.klass.scopes.include?(method) @reflection.klass.scopes[method].call(self, *args, &block) else method_missing_without_scopes(method, *args, &block) end end
Current offset of the paginated collection
# File lib/will_paginate/finders/sequel.rb, line 19 def offset (current_page - 1) * per_page end
# File lib/will_paginate/finders/sequel.rb, line 14 def out_of_bounds? current_page > total_pages end
Returns a new hash with only the given keys.
# File lib/will_paginate/core_ext.rb, line 35 def slice(*keys) allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) reject { |key,| !allowed.include?(key) } end
Replaces the hash with only the given keys.
# File lib/will_paginate/core_ext.rb, line 41 def slice!(*keys) replace(slice(*keys)) end
# File lib/will_paginate/core_ext.rb, line 61 def underscore self.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end
# File lib/will_paginate/view_helpers/merb.rb, line 7 def url(page) params = @template.request.params.except(:action, :controller).merge(param_name => page) @template.url(:this, params) end
# File lib/will_paginate/finders/active_record/named_scope_patch.rb, line 5 def with_scope(*args, &block) @reflection.klass.send :with_scope, *args, &block end