Module: Makura
- Defined in:
- lib/makura.rb,
lib/makura.rb,
lib/makura/error.rb,
lib/makura/model.rb,
lib/makura/design.rb,
lib/makura/layout.rb,
lib/makura/server.rb,
lib/makura/version.rb,
lib/makura/database.rb,
lib/makura/uuid_cache.rb,
lib/makura/http_methods.rb,
lib/makura/plugin/pager.rb,
lib/makura/plugin/localize.rb
Defined Under Namespace
Modules: HTTPMethods, Model, Plugin
Classes: Database, Design, Error, Layout, Server, UUIDCache
Constant Summary
collapse
- ROOT =
File.expand_path(File.dirname(__FILE__))
- CHARS =
(48..128).map{|c| c.chr}.grep(/[[:alnum:]]/)
- MOD =
CHARS.size
- JSON_PARAMS =
%w[key startkey endkey]
- VERSION =
"2012.01"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.constant(name, root = Module) ⇒ Object
80
81
82
|
# File 'lib/makura.rb', line 80
def constant(name, root = Module)
name.split('::').inject(root){|s,v| s.const_get(v) }
end
|
.escape(s) ⇒ Object
38
39
40
41
42
|
# File 'lib/makura.rb', line 38
def escape(s)
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/u) {
'%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
}.tr(' ', '+')
end
|
.paramify(hash) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/makura.rb', line 44
def paramify(hash)
hash.map{|k,v|
k = k.to_s
v = v.to_json if JSON_PARAMS.include?(k)
"#{escape(k)}=#{escape(v)}"
}.join('&')
end
|
.pretty_from_md5(md5) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/makura.rb', line 62
def pretty_from_md5(md5)
id = md5.to_i(16)
o = []
while id > 0
id, r = id.divmod(MOD)
o.unshift CHARS[r]
end
o.join
end
|
.pretty_to_md5(id) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/makura.rb', line 72
def pretty_to_md5(id)
i = 0
id.scan(/./) do |c|
i = i * MOD + CHARS.index(c)
end
i.to_s(16)
end
|
Instance Method Details
#bytesize(string) ⇒ Object
53
54
55
|
# File 'lib/makura.rb', line 53
def bytesize(string)
string.bytesize
end
|