dolly 0.7.1 → 0.7.2

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: 3c328e5ad0719b1db86b04f3cb37790d29f7b330
4
- data.tar.gz: 710b77307925c6fd69c21f99be59dee024234630
3
+ metadata.gz: 018a9bd659e968422dd5b822ebfc43dd72838307
4
+ data.tar.gz: 645e49f46d0e2246e12501e69c39a154d73e8885
5
5
  SHA512:
6
- metadata.gz: 9ff41bdf9958889496959bc89bec947da7f560c9e9fa008eb19c090015c2bf47bc4e53b0cd872980556b6def40f4fd8884676f86985fbad71c82cf73ee786529
7
- data.tar.gz: cda3d78ac23fc53cefa290c1cc75d7542ea1254501d58b8401f672490654661967db4d84a5b6173860dce7258e0878e40026bb7ef0911bb2d893fcbf39f4ed13
6
+ metadata.gz: 8996310eaabdf5dfbbb50e8eebc8b4a98a3fcea0cbf723da3919e948341ed555163a4def8c0f8b599580890fcda11f02ed30f559fc572bfed3a663b25ade8c52
7
+ data.tar.gz: bda2f0a5b092e2975b2ec0d3be5ed23a19b2bb1115c52cf0bc443743a1574ee18611e09c1eb48d017a319aacf5eadf86eb970a9e5fcfc21d7f8c3a6288c83c06
data/lib/dolly/query.rb CHANGED
@@ -61,6 +61,10 @@ module Dolly
61
61
  database.get doc, options
62
62
  end
63
63
 
64
+ def raw_view doc, view, opts = {}
65
+ JSON.parse database.get "_design/#{doc}/_view/#{view}", opts
66
+ end
67
+
64
68
  def timestamps!
65
69
  %i/created_at updated_at/.each do |method|
66
70
  define_method(method){ @doc[method.to_s] ||= DateTime.now }
data/lib/dolly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dolly
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
data/lib/tasks/db.rake CHANGED
@@ -7,51 +7,51 @@ namespace :db do
7
7
 
8
8
  desc "Will update design document with what is on db/designs/*.coffee"
9
9
  task design: :environment do
10
- path = File.join Rails.root, 'db', 'designs'
11
- files = Dir.glob("#{path}/*.coffee")
12
- views = {}
13
- filters = {}
10
+ design_dir = Rails.root.join 'db', 'designs'
11
+ files = Dir.glob File.join design_dir, '**', '*.coffee'
12
+ data = {}
14
13
 
15
14
  files.each do |filename|
15
+ parts = filename[design_dir.to_s.length+1..-1].split '/'
16
+ design_doc_name = parts.count == 1 ? Dolly::Document.design_doc : "_design/#{parts.first}"
17
+
16
18
  name, key = File.basename(filename).sub(/.coffee/i, '').split(/\./)
17
19
  key ||= 'map'
18
- data = File.read filename
20
+ source = File.read filename
21
+
22
+ vd = data[design_doc_name] ||= { 'views' => {}, 'filters' => {} }
19
23
 
20
24
  if key == 'filter'
21
- filters[name] ||= data
25
+ vd['filters'][name] = source
22
26
  else
23
- views[name] ||= {}
24
- views[name][key] = data
27
+ v = vd['views'][name] ||= {}
28
+ v[key] = source
25
29
  end
26
30
  end
27
31
 
28
- view_doc = {
29
- '_id' => Dolly::Document.design_doc,
30
- 'language' => 'coffeescript',
31
- 'views' => views,
32
- 'filters' => filters
33
- }
32
+ data.each do |design_doc_name, view_doc|
33
+ view_doc.merge!( '_id' => design_doc_name, 'language' => 'coffeescript')
34
34
 
35
- begin
36
- hash_doc = JSON::parse Dolly::Document.database.get(view_doc["_id"]).parsed_response
35
+ begin
36
+ hash_doc = JSON::parse Dolly::Document.database.get(view_doc["_id"]).parsed_response
37
37
 
38
- rev = hash_doc.delete('_rev')
38
+ rev = hash_doc.delete('_rev')
39
39
 
40
- if hash_doc == view_doc
41
- puts 'everything up to date'
42
- else
43
- view_doc["_rev"] = rev
44
- view_doc["views"].merge!(hash_doc['views'])
45
- puts 'updating design document'
40
+ if hash_doc == view_doc
41
+ puts 'everything up to date'
42
+ else
43
+ view_doc["_rev"] = rev
44
+ puts "Updating #{design_doc_name}"
45
+ will_save = true
46
+ end
47
+
48
+ rescue Dolly::ResourceNotFound
49
+ puts "Creating design doc: #{design_doc_name}"
46
50
  will_save = true
47
51
  end
48
52
 
49
- rescue Dolly::ResourceNotFound
50
- puts 'creating design document'
51
- will_save = true
53
+ Dolly::Document.database.put design_doc_name, view_doc.to_json if will_save
52
54
  end
53
-
54
- Dolly::Document.database.put Dolly::Document.design_doc, view_doc.to_json if will_save
55
55
  end
56
56
 
57
57
  end