dolly 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94c8771287f56c3dc8037d0847c45cde37301bf1
4
- data.tar.gz: 60819593da81aa2312205e940753e8358c72d65d
3
+ metadata.gz: 8ce659db7a91657df6f7d8d7e8e9c9eecc57b23b
4
+ data.tar.gz: 9ed99e0ffcd0d3ec81c77bdc1fa3c85c1d7eec41
5
5
  SHA512:
6
- metadata.gz: 384b3d6789af88ba43e1a3f2f7e05d863f8095625f2f3b0637b497366174361ce434bc42595257d60fca3d8e8f1b2a5bad6123b46c45f346b91b1708c2d55c21
7
- data.tar.gz: 0bf4f41521a7755687d6bae67020111f2677d9d8297c0bd72c97a1a8b4dd100cd87e51bf251ec5ee6ba63e84cead812c5fc8ac1666ed7e42f08ecc2eca3dfd20
6
+ metadata.gz: 0ea6637679a4f379356a7e03616d92827e0631bd85e737e7d3fd0f1bcb97dd33fdcdc7d1ec9fb1031e19799c64db2079db407790f79f4e7ea525609686f2aea7
7
+ data.tar.gz: b946ab815afee3855339fa13cbe11a60fd4406b5d4f78be03b408e69243a1432d9ffd72d6c37a6b28563bfb993926db5576c30647242b092058457bf245f52b2
@@ -5,6 +5,7 @@ module Dolly
5
5
  class Document
6
6
  extend Dolly::Connection
7
7
  include Dolly::Query
8
+ include Dolly::NameSpace
8
9
 
9
10
  attr_accessor :rows, :doc, :key
10
11
  class_attribute :properties
@@ -17,11 +18,21 @@ module Dolly
17
18
  doc['_id'] ||= self.class.next_id
18
19
  end
19
20
 
21
+ def id= base_value
22
+ doc ||= {}
23
+ doc['_id'] = self.class.namespace(base_value)
24
+ end
25
+
20
26
  def rev
21
27
  doc['_rev']
22
28
  end
23
29
 
30
+ def rev= value
31
+ doc['_rev'] = value
32
+ end
33
+
24
34
  def save
35
+ self.doc['_id'] = self.id if self.id.present?
25
36
  self.doc['_id'] = self.class.next_id if self.doc['_id'].blank?
26
37
  response = database.put(id_as_resource, self.doc.to_json)
27
38
  obj = JSON::parse response.parsed_response
@@ -107,7 +118,12 @@ module Dolly
107
118
  next unless respond_to? :"#{k}="
108
119
  send(:"#{k}=", v)
109
120
  end
121
+ init_doc options
122
+ end
123
+
124
+ def init_doc options
110
125
  self.doc ||= {}
126
+ self.doc['_id'] = self.class.namespace(options[:id]) if options[:id]
111
127
  end
112
128
  end
113
129
  end
data/lib/dolly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dolly
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
data/lib/tasks/db.rake CHANGED
@@ -23,4 +23,54 @@ namespace :db do
23
23
  Dolly::Document.database.put Dolly::Document.design_doc, doc.to_json
24
24
  puts "design document #{Dolly::Document.design_doc} was created/updated."
25
25
  end
26
+
27
+ desc "Will update design document with what is on db/designs/*.coffee"
28
+ task design: :environment do
29
+ path = File.join Rails.root, 'db', 'designs'
30
+ files = Dir.glob("**/*.coffee")
31
+ views = {}
32
+ filters = {}
33
+
34
+ files.each do |filename|
35
+ name, key = File.basename(filename).sub(/.coffee/i, '').split(/\./)
36
+ key ||= 'map'
37
+ data = File.read filename
38
+
39
+ if key == 'filter'
40
+ filters[name] ||= data
41
+ else
42
+ views[name] ||= {}
43
+ views[name][key] = data
44
+ end
45
+ end
46
+
47
+ view_doc = {
48
+ '_id' => Dolly::Document.design_doc,
49
+ 'language' => 'coffeescript',
50
+ 'views' => views,
51
+ 'filters' => filters
52
+ }
53
+
54
+ begin
55
+ hash_doc = JSON::parse Dolly::Document.database.get(view_doc["_id"]).parsed_response
56
+
57
+ rev = hash_doc.delete('_rev')
58
+
59
+ if hash_doc == view_doc
60
+ puts 'everything up to date'
61
+ else
62
+ view_doc["_rev"] = rev
63
+ view_doc["views"].merge!(hash_doc['views'])
64
+ puts 'updating design document'
65
+ will_save = true
66
+ end
67
+
68
+ rescue Dolly::ResourceNotFound
69
+ puts 'creating design document'
70
+ will_save = true
71
+ end
72
+
73
+ Dolly::Document.database.put Dolly::Document.design_doc, view_doc.to_json if will_save
74
+ end
75
+
26
76
  end
@@ -30772,3 +30772,90 @@ DocumentTest: test_with_default_will_return_default_value_on_nil
30772
30772
  -----------------------------------
30773
30773
  DocumentTest: test_with_timestamps!
30774
30774
  -----------------------------------
30775
+ --------------------------------------------------
30776
+ BulkDocumentTest: test_adding_document_to_bulk_doc
30777
+ --------------------------------------------------
30778
+ -----------------------------------------------------------------
30779
+ BulkDocumentTest: test_bulk_document_intialize_with_empty_payload
30780
+ -----------------------------------------------------------------
30781
+ ------------------------------------------------------------------
30782
+ BulkDocumentTest: test_save_document_will_remove_docs_from_payload
30783
+ ------------------------------------------------------------------
30784
+ --------------------------------------------------------------
30785
+ DocumentTest: test_Dolly::Document_have_bulk_document_instance
30786
+ --------------------------------------------------------------
30787
+ -------------------------------------------
30788
+ DocumentTest: test_all_first_returns_FooBar
30789
+ -------------------------------------------
30790
+ ------------------------------------------
30791
+ DocumentTest: test_all_last_returns_FooBar
30792
+ ------------------------------------------
30793
+ --------------------------------------
30794
+ DocumentTest: test_all_will_get_2_docs
30795
+ --------------------------------------
30796
+ ------------------------------------------------
30797
+ DocumentTest: test_all_will_get_FooBar_documents
30798
+ ------------------------------------------------
30799
+ ----------------------------------------------
30800
+ DocumentTest: test_default_will_be_avoerwriten
30801
+ ----------------------------------------------
30802
+ --------------------------------------------
30803
+ DocumentTest: test_delete_method_on_document
30804
+ --------------------------------------------
30805
+ ------------------------------------------------
30806
+ DocumentTest: test_empty_find_should_raise_error
30807
+ ------------------------------------------------
30808
+ ------------------------------------------------------------
30809
+ DocumentTest: test_error_on_server_raises_Dolly::ServerError
30810
+ ------------------------------------------------------------
30811
+ --------------------------------------------------
30812
+ DocumentTest: test_find_will_get_a_FooBar_document
30813
+ --------------------------------------------------
30814
+ ----------------------------------------------------------------
30815
+ DocumentTest: test_find_with_multiple_ids_will_return_Collection
30816
+ ----------------------------------------------------------------
30817
+ --------------------------------------------------------
30818
+ DocumentTest: test_first_class_method_returns_collection
30819
+ --------------------------------------------------------
30820
+ ---------------------------------------------------------
30821
+ DocumentTest: test_first_class_method_returns_single_item
30822
+ ---------------------------------------------------------
30823
+ ---------------------------------------------
30824
+ DocumentTest: test_getting_not_found_document
30825
+ ---------------------------------------------
30826
+ -------------------------------------------------------
30827
+ DocumentTest: test_last_class_method_returns_collection
30828
+ -------------------------------------------------------
30829
+ --------------------------------------------------------
30830
+ DocumentTest: test_last_class_method_returns_single_item
30831
+ --------------------------------------------------------
30832
+ -------------------------------------------------
30833
+ DocumentTest: test_multi_response_with_right_data
30834
+ -------------------------------------------------
30835
+ ---------------------------------------
30836
+ DocumentTest: test_new_document_have_id
30837
+ ---------------------------------------
30838
+ -----------------------------------------
30839
+ DocumentTest: test_new_in_memory_document
30840
+ -----------------------------------------
30841
+ ------------------------------------
30842
+ DocumentTest: test_query_custom_view
30843
+ ------------------------------------
30844
+ ------------------------------------------
30845
+ DocumentTest: test_soft_delete_on_document
30846
+ ------------------------------------------
30847
+ -------------------------------------------
30848
+ DocumentTest: test_will_have_key_properties
30849
+ -------------------------------------------
30850
+ --------------------------------------------------------
30851
+ DocumentTest: test_will_have_object_with_boolean?_method
30852
+ --------------------------------------------------------
30853
+ ------------------------------------------------
30854
+ DocumentTest: test_will_have_only_set_properties
30855
+ ------------------------------------------------
30856
+ ----------------------------------------------------------------
30857
+ DocumentTest: test_with_default_will_return_default_value_on_nil
30858
+ ----------------------------------------------------------------
30859
+ -----------------------------------
30860
+ DocumentTest: test_with_timestamps!
30861
+ -----------------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - javierg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2013-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails