class Object
Public Instance Methods
constantize()
click to toggle source
# File lib/leaf/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
except(*keys)
click to toggle source
Returns a new hash without the given keys.
# File lib/leaf/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
except!(*keys)
click to toggle source
Replaces the hash without only the given keys.
# File lib/leaf/core_ext.rb, line 26 def except!(*keys) replace(except(*keys)) end
offset()
click to toggle source
Current offset of the paginated collection
# File lib/leaf/finders/sequel.rb, line 20 def offset (current_page - 1) * per_page end
out_of_bounds?()
click to toggle source
# File lib/leaf/finders/sequel.rb, line 15 def out_of_bounds? current_page > total_pages end
slice(*keys)
click to toggle source
Returns a new hash with only the given keys.
# File lib/leaf/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
slice!(*keys)
click to toggle source
Replaces the hash with only the given keys.
# File lib/leaf/core_ext.rb, line 41 def slice!(*keys) replace(slice(*keys)) end
underscore()
click to toggle source
# File lib/leaf/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
url(page)
click to toggle source
# File lib/leaf/view_helpers/sinatra.rb, line 7 def url(page) url = @template.request.url if page == 1 # strip out page param and trailing ? and & if they exists url.gsub(/(\?|\&)page=[0-9]+/, '').gsub(/\?$/, '').gsub(/\&$/, '') else if url =~ /(\?|\&)page=[0-9]+/ url.gsub(/page=[0-9]+/, "page=#{page}").gsub(/\&+/, '&') else (url =~ /\?/) ? url + "&page=#{page}" : url + "?page=#{page}" end end end