Class: Gin
- Inherits:
-
Object
- Object
- Gin
- Defined in:
- lib/gin.rb
Defined Under Namespace
Modules: Constants, Errorable, Filterable, Mountable, Reloadable, Test Classes: App, AssetManifest, AssetPipeline, BadRequest, Cache, Config, Controller, Error, MissingConfig, NotFound, RWLock, Request, Response, Router, RouterError, Stream, StrictHash, TemplateMissing, Worker
Constant Summary collapse
- VERSION =
'1.2.1'
- LIB_DIR =
:nodoc:
File.("..", __FILE__)
- PUBLIC_DIR =
:nodoc:
File.("../../public/", __FILE__)
- APP_START_MATCH =
:nodoc:
%r{/gin/app\.rb:\d+:in `dispatch'}
Class Method Summary collapse
-
.app_trace(trace) ⇒ Object
Get the application backtrace only.
-
.build_query(value, prefix = nil) ⇒ Object
Create a URI query from a Hash.
-
.camelize(str) ⇒ Object
Change string to camel-case version.
-
.const_find(str_or_ary, parent = Object) ⇒ Object
Get a namespaced constant.
-
.find_loadpath(file) ⇒ Object
Returns the full path to the file given based on the load paths.
-
.underscore(str) ⇒ Object
Change string to underscored version.
Class Method Details
.app_trace(trace) ⇒ Object
Get the application backtrace only. Removes gem and Gin paths from the trace.
118 119 120 121 122 123 |
# File 'lib/gin.rb', line 118 def self.app_trace trace trace = trace.dup trace.pop until trace.last.nil? || trace.last =~ APP_START_MATCH trace.pop while trace.last && trace.last.start_with?(LIB_DIR) trace end |
.build_query(value, prefix = nil) ⇒ Object
Create a URI query from a Hash.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gin.rb', line 53 def self.build_query value, prefix=nil case value when Array raise ArgumentError, "no prefix given" if prefix.nil? value.map { |v| build_query(v, "#{prefix}[]") }.join("&") when Hash value.map { |k, v| build_query(v, prefix ? "#{prefix}[#{CGI.escape(k.to_s)}]" : CGI.escape(k.to_s)) }.join("&") when String, Integer, Float, TrueClass, FalseClass raise ArgumentError, "value must be a Hash" if prefix.nil? "#{prefix}=#{CGI.escape(value.to_s)}" else prefix end end |
.camelize(str) ⇒ Object
Change string to camel-case version.
43 44 45 46 47 |
# File 'lib/gin.rb', line 43 def self.camelize str str = str.dup str.gsub!(/\/([^_:])/){|m| "::#{$1.upcase}" } str.gsub!(/(^|_+)([^_:])/){|m| $2.upcase } end |
.const_find(str_or_ary, parent = Object) ⇒ Object
Get a namespaced constant.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gin.rb', line 100 def self.const_find str_or_ary, parent=Object const = nil names = Array === str_or_ary ? str_or_ary : str_or_ary.split("::") names.each do |name| const = parent.const_get(name) parent = const end const end |
.find_loadpath(file) ⇒ Object
Returns the full path to the file given based on the load paths.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gin.rb', line 80 def self.find_loadpath file name = file.dup name << ".rb" unless name[-3..-1] == ".rb" return name if name[0] == ?/ && File.file?(name) filepath = nil dir = $:.find do |path| filepath = File.(name, path) File.file? filepath end dir && filepath end |
.underscore(str) ⇒ Object
Change string to underscored version.
31 32 33 34 35 36 37 |
# File 'lib/gin.rb', line 31 def self.underscore str str = str.dup str.gsub!('::', '/') str.gsub!(/([A-Z]+?)([A-Z][a-z])/, '\1_\2') str.gsub!(/([a-z\d])([A-Z])/, '\1_\2') str.downcase end |