makura 2010.08.26 → 2011.01.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Following persons have contributed to makura.
2
2
  (Sorted by number of submitted patches, then alphabetically)
3
3
 
4
- 82 Michael Fellinger <m.fellinger@gmail.com>
4
+ 88 Michael Fellinger <m.fellinger@gmail.com>
5
5
  8 Tadahiko Uehara <kikofx@gmail.com>
6
6
  2 Preston Marshall <preston@synergy-solutions.biz>
@@ -1,3 +1,27 @@
1
+ [f605cce | Thu Jan 20 16:12:17 UTC 2011] Michael Fellinger <m.fellinger@gmail.com>
2
+
3
+ * Move Makura::Server#paramify to Makura::paramify to allow reuse
4
+
5
+ [c136984 | Tue Oct 12 11:20:18 UTC 2010] Michael Fellinger <m.fellinger@gmail.com>
6
+
7
+ * Fix validation in Model#save, it checked for the wrong method name.
8
+
9
+ [b236bcb | Mon Oct 04 13:18:39 UTC 2010] Michael Fellinger <m.fellinger@gmail.com>
10
+
11
+ * design is not an optional argument
12
+
13
+ [ea03df7 | Thu Sep 30 01:02:39 UTC 2010] Michael Fellinger <m.fellinger@gmail.com>
14
+
15
+ * Make escape compatible with unicode
16
+
17
+ [37c2281 | Tue Sep 28 11:15:21 UTC 2010] Michael Fellinger <m.fellinger@gmail.com>
18
+
19
+ * Allow for _sum _count and _stats as builtin functions
20
+
21
+ [afd5ba8 | Tue Sep 28 11:15:08 UTC 2010] Michael Fellinger <m.fellinger@gmail.com>
22
+
23
+ * Add ServerBrokeConnection to exceptions
24
+
1
25
  [b7479a6 | Wed Aug 25 16:26:05 UTC 2010] Michael Fellinger <m.fellinger@gmail.com>
2
26
 
3
27
  * Version 2010.08.26
@@ -30,16 +30,35 @@ require 'makura/layout'
30
30
  module Makura
31
31
  CHARS = (48..128).map{|c| c.chr}.grep(/[[:alnum:]]/)
32
32
  MOD = CHARS.size
33
+ JSON_PARAMS = %w[key startkey endkey]
33
34
 
34
35
  module_function
35
36
 
36
37
  # From Rack
37
38
  def escape(s)
38
- s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
39
- '%'+$1.unpack('H2'*$1.size).join('%').upcase
39
+ s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/u) {
40
+ '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
40
41
  }.tr(' ', '+')
41
42
  end
42
43
 
44
+ def paramify(hash)
45
+ hash.map{|k,v|
46
+ k = k.to_s
47
+ v = v.to_json if JSON_PARAMS.include?(k)
48
+ "#{escape(k)}=#{escape(v)}"
49
+ }.join('&')
50
+ end
51
+
52
+ if "".respond_to?(:bytesize)
53
+ def bytesize(string)
54
+ string.bytesize
55
+ end
56
+ else
57
+ def bytesize(string)
58
+ string.size
59
+ end
60
+ end
61
+
43
62
  def pretty_from_md5(md5)
44
63
  id = md5.to_i(16)
45
64
  o = []
@@ -4,6 +4,7 @@ module Makura
4
4
  class ConnectionRefused < Error; end
5
5
  class RequestFailed < Error; end
6
6
  class ResourceNotFound < RequestFailed; end
7
+ class ServerBrokeConnection < RequestFailed; end
7
8
  class Conflict < RequestFailed; end
8
9
  class MissingRevision < RequestFailed; end
9
10
  class BadRequest < RequestFailed; end
@@ -7,7 +7,7 @@ module Makura
7
7
  File.join(Makura::ROOT, '../couch')
8
8
  ]
9
9
 
10
- def initialize(name, design = nil)
10
+ def initialize(name, design)
11
11
  @name, @design = name, design
12
12
  @design[name] = self
13
13
  @map = @reduce = nil
@@ -37,7 +37,8 @@ module Makura
37
37
  def common_load(type, file_or_function)
38
38
  return unless file_or_function
39
39
 
40
- if file_or_function =~ /function\(.*\)/
40
+ case file_or_function
41
+ when /function\(.*\)/, /^_(sum|count|stats)$/
41
42
  function = file_or_function
42
43
  else
43
44
  parts = file_or_function.to_s.split('::')
@@ -85,7 +85,7 @@ module Makura
85
85
  end
86
86
 
87
87
  def save
88
- return if not valid? if respond_to?(:valid)
88
+ return unless valid? if respond_to?(:valid?)
89
89
  save!
90
90
  end
91
91
 
@@ -145,6 +145,8 @@ module Makura
145
145
  return raw
146
146
  rescue RestClient::RequestFailed => ex
147
147
  raise appropriate_error(ex)
148
+ rescue RestClient::ServerBrokeConnection => ex
149
+ raise Error::ServerBrokeConnection, request[:url], ex.backtrace
148
150
  rescue RestClient::ResourceNotFound => ex
149
151
  raise Error::ResourceNotFound, request[:url], ex.backtrace
150
152
  rescue Errno::ECONNREFUSED
@@ -183,20 +185,10 @@ module Makura
183
185
  end
184
186
  end
185
187
 
186
- JSON_PARAMS = %w[key startkey endkey]
187
-
188
- def paramify(hash)
189
- hash.map{|k,v|
190
- k = k.to_s
191
- v = v.to_json if JSON_PARAMS.include?(k)
192
- "#{Makura.escape(k)}=#{Makura.escape(v)}"
193
- }.join('&')
194
- end
195
-
196
188
  def uri(path = '/', params = {})
197
189
  uri = @uri.dup
198
190
  uri.path = (path[0,1] == '/' ? path : "/#{path}").squeeze('/')
199
- uri.query = paramify(params) unless params.empty?
191
+ uri.query = Makura.paramify(params) unless params.empty?
200
192
  uri
201
193
  end
202
194
  end
@@ -1,3 +1,3 @@
1
1
  module Makura
2
- VERSION = "2010.08.26"
2
+ VERSION = "2011.01.21"
3
3
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{makura}
5
- s.version = "2010.08.26"
5
+ s.version = "2011.01.21"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Michael 'manveru' Fellinger"]
9
- s.date = %q{2010-08-26}
9
+ s.date = %q{2011-01-21}
10
10
  s.default_executable = %q{makura}
11
11
  s.email = %q{m.fellinger@gmail.com}
12
12
  s.executables = ["makura"]
metadata CHANGED
@@ -3,10 +3,10 @@ name: makura
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 2010
7
- - 8
8
- - 26
9
- version: 2010.08.26
6
+ - 2011
7
+ - 1
8
+ - 21
9
+ version: 2011.01.21
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael 'manveru' Fellinger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-26 00:00:00 +09:00
17
+ date: 2011-01-21 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency