Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

Dolly is a Object Oriented CouchDB interface to interact with the JSON documents through CouchDB's RESTful API.

## Versions

### Dolly 1.x

It is only compatible with CouchDB 1.x

### Dolly 2.x

Dolly 2.x is compatible only with CouchDB 2.x and up

#### Braking changes

* Due to fix on HTTParty, now `parsed_response` returns a `Hash` instead of a `JSON` string.
So no need to call `JSON.parse` on db responses.
* CochDB 2.0 will not accept post requests to views without a rquest body.
* No need to call `to_json` on body values for requests

## Installation

Add this line to your application's Gemfile:
Expand Down
11 changes: 5 additions & 6 deletions lib/dolly/collection.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Dolly
class Collection < DelegateClass(Set)
attr_accessor :rows
attr_accessor :rows, :collection
attr_writer :json, :docs_class

def initialize str, docs_class
def initialize collection, docs_class
@docs_class = docs_class
@json = str
@collection = collection
initial = []
super(initial)
load
Expand Down Expand Up @@ -57,8 +57,7 @@ def rows= ary
end

def load
parsed = JSON::parse json
self.rows = parsed['rows']
self.rows = collection['rows']
end

def to_json options = {}
Expand All @@ -81,7 +80,7 @@ def doc_class id
end

def json
@json
@json ||= @collection.to_json
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/dolly/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def save options = {}
set_created_at if timestamps[self.class.name]
set_updated_at if timestamps[self.class.name]
response = database.put(id_as_resource, self.doc.to_json)
obj = JSON::parse response.parsed_response
obj = response.parsed_response
doc['_rev'] = obj['rev'] if obj['rev']
obj['ok']
end
Expand All @@ -78,7 +78,7 @@ def destroy hard = true
if hard
q = id_as_resource + "?rev=#{rev}"
response = database.delete(q)
JSON::parse response.parsed_response
response.parsed_response
else
self.doc['_deleted'] = true
self.save
Expand Down
2 changes: 1 addition & 1 deletion lib/dolly/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Property
attr_accessor :name
attr_reader :class_name, :default

CANT_CLONE = [NilClass, TrueClass, FalseClass, Fixnum].freeze
CANT_CLONE = [NilClass, TrueClass, FalseClass, Integer].freeze

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this, in order to be useful in a lot of places, should be determined based on the version of ruby (as I think that is the change in this no?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmh, right, this is not related to the ruby version
will remove the change as it is not related to the errors associated to httparty parsed response

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 ya i think a PR for that on its own makes sense. I could see a singleton of a DelegateClass Array here as a feasible way to handle that


def initialize opts = {}
@class_name = opts.delete(:class_name) if opts.present?
Expand Down
4 changes: 2 additions & 2 deletions lib/dolly/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def find *keys
if keys.count > 1
build_collection( query_hash )
else
self.new.from_json( database.all_docs(query_hash).parsed_response )
self.new( database.all_docs(query_hash).parsed_response )
end
rescue NoMethodError => err
if err.message == "undefined method `[]' for nil:NilClass"
Expand Down Expand Up @@ -72,7 +72,7 @@ def view doc, options = {}
end

def raw_view doc, view, opts = {}
JSON.parse database.get "_design/#{doc}/_view/#{view}", opts
database.get "_design/#{doc}/_view/#{view}", opts
end

end
Expand Down
3 changes: 2 additions & 1 deletion lib/dolly/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ def request method, resource, data = nil
end

private

def tools path, opts = nil
data = {}
q = "?#{CGI.unescape(opts.to_query)}" unless opts.blank?
data.merge!(basic_auth: auth_info) if auth_info.present?
JSON::parse self.class.get("/#{path}#{q}", data)
self.class.get("/#{path}#{q}", data)
end

def auth_info
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace :db do
view_doc.merge!( '_id' => design_doc_name, 'language' => 'coffeescript')

begin
hash_doc = JSON::parse Dolly::Document.database.get(view_doc["_id"]).parsed_response
hash_doc = Dolly::Document.database.get(view_doc["_id"]).parsed_response

rev = hash_doc.delete('_rev')

Expand Down