throne 0.0.3 → 0.0.4

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,4 +1,4 @@
1
- require 'yajl/json_gem'
1
+ require 'yajl'
2
2
  require 'rest_client'
3
3
  require 'hashie'
4
4
 
@@ -16,7 +16,7 @@ class Throne::Database
16
16
  # Creates this database, will not error if the database exists
17
17
  def create_database
18
18
  begin
19
- c.put @url, {}
19
+ C.put @url, {}
20
20
  rescue RestClient::RequestFailed => e
21
21
  unless e.message =~ /412$/
22
22
  raise e
@@ -27,7 +27,7 @@ class Throne::Database
27
27
  # deletes this database.
28
28
  def delete_database
29
29
  begin
30
- c.delete @url
30
+ C.delete @url
31
31
  rescue RestClient::ResourceNotFound
32
32
  end
33
33
  end
@@ -40,7 +40,7 @@ class Throne::Database
40
40
  def get(docid, rev=nil)
41
41
  begin
42
42
  revurl = rev ? "?rev=#{rev}" : ""
43
- Hashie::Mash.new(JSON.parse(c.get(@url + '/' + docid + revurl)))
43
+ Hashie::Mash.new(JP.parse(C.get(@url + '/' + docid + revurl)))
44
44
  rescue RestClient::ResourceNotFound
45
45
  nil
46
46
  end
@@ -49,11 +49,11 @@ class Throne::Database
49
49
  # creates/updates a document from a hash/array structure
50
50
  def save(doc)
51
51
  if id = doc['_id']
52
- res = c.put(@url + '/' + id, doc.to_json)
52
+ res = C.put(@url + '/' + id, JE.encode(doc))
53
53
  else
54
- res = c.post(@url, doc.to_json)
54
+ res = C.post(@url, JE.encode(doc))
55
55
  end
56
- res = JSON.parse(res)
56
+ res = JP.parse(res)
57
57
  return nil unless res['ok']
58
58
  Throne::StringWithRevision.new(res['id'], res['rev'])
59
59
  end
@@ -67,18 +67,26 @@ class Throne::Database
67
67
  doc = doc['_id']
68
68
  end
69
69
 
70
- c.delete(@url + '/' + doc + '?rev=' + rev)
70
+ C.delete(@url + '/' + doc + '?rev=' + rev)
71
71
  end
72
72
 
73
- # runs a function by path, with optional params passed in
74
- def function(path, params = {}, &block)
73
+ # runs a function by path, returning an array of results.
74
+ def function(path, params = {})
75
+ items = []
76
+ function_iter(path, params) {|i| items << i}
77
+ items
78
+ end
79
+
80
+
81
+ # runs a function by path, invoking once for each item.
82
+ def function_iter(path, params = {}, &block)
75
83
  url = @url + '/' + path
76
- res = JSON.parse(c.get(paramify_url(url, params)))
84
+ res = JP.parse(C.get(paramify_url(url, params)))
77
85
  res = Throne::ArrayWithFunctionMeta.new(res['rows'], res['offset'])
78
86
  if block_given?
79
- # TODO - stream properly
87
+ # TODO - stream properly, need to get objects.
80
88
  res.each do |i|
81
- yield i
89
+ yield Hashie::Mash.new(i)
82
90
  end
83
91
  nil
84
92
  else
@@ -91,7 +99,7 @@ class Throne::Database
91
99
  def paramify_url url, params = {}
92
100
  if params && !params.empty?
93
101
  query = params.collect do |k,v|
94
- v = v.to_json if %w{key startkey endkey}.include?(k.to_s) &&
102
+ v = JE.encode(v) if %w{key startkey endkey}.include?(k.to_s) &&
95
103
  (v.kind_of?(Array) || v.kind_of?(Hash))
96
104
  "#{k}=#{CGI.escape(v.to_s)}"
97
105
  end.join("&")
@@ -101,7 +109,10 @@ class Throne::Database
101
109
  end
102
110
 
103
111
 
104
- def c; RestClient; end
112
+ C = RestClient
113
+ # This is so I can switch stuff later.
114
+ JP = Yajl::Parser
115
+ JE = Yajl::Encoder
105
116
  end
106
117
 
107
118
  # Extended string, to store the couch revision
@@ -2,10 +2,11 @@ require 'yaml'
2
2
 
3
3
  # Defines tasks for managing databases and views.
4
4
  #
5
- # To reference a file in lib/ from your design doc, use a commend like this
6
- # // !code library.js
5
+ # To reference a file in lib/ from your design doc, use a comment like this
6
+ #
7
+ # // !code library.js
7
8
  #
8
- # This will include the contents at this locate.
9
+ # This will include the contents at this location.
9
10
  #
10
11
  # These tasks require an environment variable of SERVER_URL to be set.
11
12
  #
@@ -13,38 +14,38 @@ require 'yaml'
13
14
  # root of base path will be included in all databases, items with a database will be
14
15
  # included into that database only.
15
16
  #
16
- # base_path/
17
- # |-- lib
18
- # | `-- library.js
19
- # |-- data
20
- # | `-- .json and .yml folders with seed data
21
- # |-- design
22
- # | `-- <design doc name>
23
- # | |-- lists
24
- # | | `-- listname.js
25
- # | |-- shows
26
- # | | `-- showname.js
27
- # | |-- validate_doc_update.sh
28
- # | `-- views
29
- # | `-- statuses
30
- # | |-- map.js
31
- # | `-- reduce.js
32
- # |-- <db name>
17
+ # base_path/
33
18
  # |-- lib
34
19
  # | `-- library.js
35
20
  # |-- data
36
21
  # | `-- .json and .yml folders with seed data
37
- # `-- design
38
- # `-- <design doc name>
39
- # |-- lists
40
- # | `-- listname.js
41
- # |-- shows
42
- # | `-- showname.js
43
- # |-- validate_doc_update.sh
44
- # `-- views
45
- # `-- statuses
46
- # |-- map.js
47
- # `-- reduce.js
22
+ # |-- design
23
+ # | `-- <design doc name>
24
+ # | |-- lists
25
+ # | | `-- listname.js
26
+ # | |-- shows
27
+ # | | `-- showname.js
28
+ # | |-- validate_doc_update.js
29
+ # | `-- views
30
+ # | `-- statuses
31
+ # | |-- map.js
32
+ # | `-- reduce.js
33
+ # |-- <db name>
34
+ # |-- lib
35
+ # | `-- library.js
36
+ # |-- data
37
+ # | `-- .json and .yml folders with seed data
38
+ # `-- design
39
+ # `-- <design doc name>
40
+ # |-- lists
41
+ # | `-- listname.js
42
+ # |-- shows
43
+ # | `-- showname.js
44
+ # |-- validate_doc_update.js
45
+ # `-- views
46
+ # `-- statuses
47
+ # |-- map.js
48
+ # `-- reduce.js
48
49
  #
49
50
  class Throne::Tasks
50
51
  # This will inject Rake tasks for managing the database data. The base path should
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{throne}
8
+ s.version = "0.0.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Lincoln Stoll"]
12
+ s.date = %q{2009-12-17}
13
+ s.description = %q{Simple library for working with CouchDB. Avoids magic, keeps it simple.}
14
+ s.email = %q{lstoll@lstoll.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc",
18
+ "TODO"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "TODO",
27
+ "VERSION",
28
+ "lib/throne.rb",
29
+ "lib/throne/database.rb",
30
+ "lib/throne/document.rb",
31
+ "lib/throne/tasks.rb",
32
+ "spec/database_spec.rb",
33
+ "spec/document_spec.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb",
36
+ "spec/tasks_spec.rb",
37
+ "throne.gemspec"
38
+ ]
39
+ s.homepage = %q{http://github.com/lstoll/throne}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{Simple CouchDB library}
44
+ s.test_files = [
45
+ "spec/database_spec.rb",
46
+ "spec/document_spec.rb",
47
+ "spec/spec_helper.rb",
48
+ "spec/tasks_spec.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
58
+ s.add_runtime_dependency(%q<hashie>, [">= 0"])
59
+ s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
+ s.add_dependency(%q<rest-client>, [">= 0"])
63
+ s.add_dependency(%q<hashie>, [">= 0"])
64
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
68
+ s.add_dependency(%q<rest-client>, [">= 0"])
69
+ s.add_dependency(%q<hashie>, [">= 0"])
70
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
71
+ end
72
+ end
73
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: throne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lincoln Stoll
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-16 00:00:00 +11:00
12
+ date: 2009-12-17 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,7 @@ files:
79
79
  - spec/spec.opts
80
80
  - spec/spec_helper.rb
81
81
  - spec/tasks_spec.rb
82
+ - throne.gemspec
82
83
  has_rdoc: true
83
84
  homepage: http://github.com/lstoll/throne
84
85
  licenses: []