mongous 0.1.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +216 -44
  3. data/README.ja.adoc +217 -45
  4. data/lib/mongous/base.rb +30 -0
  5. data/lib/mongous/document.rb +75 -32
  6. data/lib/mongous/extention.rb +55 -46
  7. data/lib/mongous/filter.rb +82 -60
  8. data/lib/mongous/version.rb +1 -1
  9. data/sample/connect_auto_2.rb +2 -1
  10. data/sample/connect_default_2.rb +2 -1
  11. data/sample/connect_environ_2.rb +2 -1
  12. data/sample/connect_loadfile_2.rb +2 -1
  13. data/sample/declare_compact_1.rb +7 -7
  14. data/sample/declare_label_1.rb +10 -6
  15. data/sample/declare_ndex_1.rb +9 -5
  16. data/sample/declare_ndex_2.rb +10 -6
  17. data/sample/declare_strict_1.rb +14 -10
  18. data/sample/declare_strict_2.rb +5 -3
  19. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
  20. data/sample/multi_collection_2.rb +63 -0
  21. data/sample/multi_collection_3.rb +26 -0
  22. data/sample/query_basic_1.rb +3 -1
  23. data/sample/query_basic_2.rb +5 -3
  24. data/sample/query_basic_3.rb +2 -3
  25. data/sample/query_basic_4.rb +3 -4
  26. data/sample/query_basic_5.rb +2 -3
  27. data/sample/query_detail_1.rb +3 -1
  28. data/sample/query_detail_2.rb +3 -1
  29. data/sample/query_detail_3.rb +5 -3
  30. data/sample/{query_basic_6.rb → query_filter_1.rb} +8 -5
  31. data/sample/query_filter_2.rb +50 -0
  32. data/sample/{query_super_1.rb → query_find_1.rb} +0 -1
  33. data/sample/query_projection_1.rb +5 -8
  34. data/sample/query_skip_limit_1.rb +47 -0
  35. data/sample/query_skip_limit_2.rb +49 -0
  36. data/sample/query_sort_order_1.rb +46 -0
  37. data/sample/save_basic_1.rb +1 -2
  38. data/sample/save_basic_2.rb +1 -2
  39. data/sample/save_basic_3.rb +1 -2
  40. data/sample/save_detail_1.rb +7 -4
  41. data/sample/save_detail_2.rb +7 -4
  42. data/sample/save_detail_3.rb +11 -8
  43. data/sample/save_verify_1.rb +7 -4
  44. data/sample/save_verify_3.rb +1 -1
  45. data/sample/save_verify_5.rb +3 -3
  46. data/sample/save_verify_6.rb +3 -3
  47. data/sample/save_verify_7.rb +23 -0
  48. data/sample/update_basic_1.rb +13 -0
  49. data/sample/zap_basic_2.rb +2 -2
  50. data/sample/zap_basic_3.rb +2 -2
  51. data/sample/zbenchmark_search_1.rb +110 -0
  52. data/sample/zbenchmark_search_2.rb +110 -0
  53. metadata +15 -10
  54. data/sample/multi_docs_2.rb +0 -58
  55. data/sample/query_limit_1.rb +0 -44
  56. data/sample/query_order_1.rb +0 -49
  57. data/sample/template_article.rb +0 -5
  58. data/sample/template_person.rb +0 -12
@@ -1,3 +1,3 @@
1
1
  module Mongous
2
- VERSION = "0.1.5"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,7 +5,8 @@ $client = Mongous.connect
5
5
 
6
6
  class Book
7
7
  include Mongous::Document
8
- set_client $client
8
+ self.client = $client
9
+ self.collection_name = "Book"
9
10
  end
10
11
 
11
12
 
@@ -5,7 +5,8 @@ $client = Mongous.connect( ["localhost:27017"], database: "test" )
5
5
 
6
6
  class Book
7
7
  include Mongous::Document
8
- set_client $client
8
+ self.client = $client
9
+ self.collection_name = "Book"
9
10
  end
10
11
 
11
12
 
@@ -5,7 +5,8 @@ $client = Mongous.connect( ENV["MONGOLAB_URI"] || "mongodb://localhost:27017/t
5
5
 
6
6
  class Book
7
7
  include Mongous::Document
8
- set_client $client
8
+ self.client = $client
9
+ self.collection_name = "Book"
9
10
  end
10
11
 
11
12
 
@@ -6,7 +6,8 @@ $client = Mongous.connect( file: filepath, mode: ENV["RACK_ENV"] || "developme
6
6
 
7
7
  class Book
8
8
  include Mongous::Document
9
- set_client $client
9
+ self.client = $client
10
+ self.collection_name = "Book"
10
11
  end
11
12
 
12
13
 
@@ -7,20 +7,20 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
10
  book = Book.new
12
- book.title = "title compact"
13
- book.author = "foobar"
11
+ book.title = "declare compact"
12
+ book.author = "Alice"
14
13
  book.publisher = nil
15
- book.style = "A4"
14
+ book.style = "hardcover"
15
+ book.size = "A4"
16
16
  book.price = 100
17
17
  book.page = 100
18
- # book.publish_at = nil # (default)
19
- # book.isbn = "978-3-16-148410-0"
18
+ book.isbn = "978-3-16-148410-0"
20
19
  # book.lang = nil # (default)
20
+ # book.created_at = nil # (created)
21
+ # book.updated_at = nil # (updated)
21
22
  book.save
22
23
 
23
-
24
24
  Book.each do |book|
25
25
  pp book
26
26
  end
@@ -10,26 +10,30 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price
14
15
  field :page
15
- field :publish_at
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at
19
+ field :updated_at
18
20
 
19
21
  verify :strict
20
22
  end
21
23
 
22
24
 
23
25
  book = Book.new
24
- book.title = "title label"
25
- book.author = "foobar"
26
+ book.title = "declare label"
27
+ book.author = "Bob"
26
28
  book.publisher = nil
27
- book.style = "A5"
29
+ book.style = "softcover"
30
+ book.size = "A5"
28
31
  book.price = 200
29
32
  book.page = 200
30
- # book.publish_at = nil # (default)
31
- # book.isbn = "978-3-16-148410-0"
33
+ book.isbn = "978-3-16-148410-0"
32
34
  # book.lang = nil # (default)
35
+ # book.created_at = nil # (created)
36
+ # book.updated_at = nil # (updated)
33
37
  book.save
34
38
 
35
39
 
@@ -10,11 +10,13 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price
14
15
  field :page
15
- field :publish_at
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at
19
+ field :updated_at
18
20
 
19
21
  index :title
20
22
 
@@ -23,15 +25,17 @@ end
23
25
 
24
26
 
25
27
  book = Book.new
26
- book.title = "title strict"
27
- book.author = "foobar"
28
+ book.title = "declare index 1"
29
+ book.author = "Candy"
28
30
  book.publisher = nil
29
- book.style = "A6"
31
+ book.style = "paperback"
32
+ book.size = "A6"
30
33
  book.price = 300
31
34
  book.page = 300
32
- # book.publish_at = nil # (default)
33
35
  book.isbn = "978-3-16-148410-0"
34
36
  # book.lang = nil # (default)
37
+ # book.created_at = nil # (created)
38
+ # book.updated_at = nil # (updated)
35
39
  book.save
36
40
 
37
41
 
@@ -10,28 +10,32 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price
14
15
  field :page
15
- field :publish_at
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at
19
+ field :updated_at
18
20
 
19
- index :isbn, unique: true
21
+ index :isbn
20
22
 
21
23
  verify :strict
22
24
  end
23
25
 
24
26
 
25
27
  book = Book.new
26
- book.title = "title strict"
27
- book.author = "foobar"
28
+ book.title = "declare index 2"
29
+ book.author = "Candy"
28
30
  book.publisher = nil
29
- book.style = "A6"
31
+ book.style = "paperback"
32
+ book.size = "A6"
30
33
  book.price = 300
31
34
  book.page = 300
32
- # book.publish_at = nil # (default)
33
35
  book.isbn = "978-3-16-148410-0"
34
36
  # book.lang = nil # (default)
37
+ # book.created_at = nil # (created)
38
+ # book.updated_at = nil # (updated)
35
39
  book.save
36
40
 
37
41
 
@@ -9,12 +9,14 @@ class Book
9
9
  field :title, String, :must
10
10
  field :author, String
11
11
  field :publisher, String
12
- field :style, String, %w[A4 A5 A6]
12
+ field :style, String, %w[hardcover softcover paperback]
13
+ field :size, String, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
15
  field :page, Integer, proc{ page % 4 == 0 }
15
- field :publish_at, Date, &proc{ Date.today }
16
16
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
17
+ field :lang, String, default: "en"
18
+ field :created_at, Time, create: proc{ Time.now }
19
+ field :updated_at, Time, update: proc{ Time.now }
18
20
 
19
21
  verify :strict
20
22
  verify { having?( title ) }
@@ -23,21 +25,23 @@ class Book
23
25
  end
24
26
 
25
27
  def isbn?
26
- isbn&.gsub(/\D*/, '')&.size == 13
28
+ isbn.gsub(/\D*/, '').size == 13
27
29
  end
28
30
  end
29
31
 
30
32
 
31
33
  book = Book.new
32
- book.title = "title strict"
33
- book.author = "foobar"
34
+ book.title = "declare strict"
35
+ book.author = "David"
34
36
  book.publisher = nil
35
- book.style = "A6"
36
- book.price = 300
37
- book.page = 300
38
- # book.publish_at = nil # (default)
37
+ book.style = "paperback"
38
+ book.size = "A7"
39
+ book.price = 400
40
+ book.page = 400
39
41
  book.isbn = "978-3-16-148410-0"
40
42
  # book.lang = nil # (default)
43
+ # book.created_at = nil # (create)
44
+ # book.updated_at = nil # (update)
41
45
  book.save
42
46
 
43
47
 
@@ -9,12 +9,14 @@ class Book
9
9
  field :title, String, :must
10
10
  field :author, String
11
11
  field :publisher, String, :must
12
- field :style, String, %w[A4 A5 A6]
12
+ field :style, String, %w[hardcover softcover paperback]
13
+ field :size, String, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
15
  field :page, Integer, proc{ page % 4 == 0 }
15
- field :publish_at, Date, &proc{ Date.today }
16
16
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
17
+ field :lang, String, default: "en"
18
+ field :created_at, Time, create: proc{ Time.now }
19
+ field :updated_at, Time, update: proc{ Time.now }
18
20
 
19
21
  verify :strict
20
22
 
@@ -0,0 +1,63 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book1
7
+ include Mongous::Document
8
+ end
9
+
10
+ class Book2
11
+ include Mongous::Document
12
+
13
+ field :title
14
+ field :author
15
+ field :publisher
16
+ field :style
17
+ field :size
18
+ field :price
19
+ field :page
20
+ field :isbn
21
+ field :lang
22
+ field :created_at
23
+ field :updated_at
24
+
25
+ verify :strict
26
+ end
27
+
28
+ class Book3
29
+ include Mongous::Document
30
+
31
+ field :title, :must
32
+ field :author
33
+ field :publisher, String, :must
34
+ field :style, String, %w[hardcover softcover paperback]
35
+ field :size, String, /[AB]\d/
36
+ field :price, Integer, (0..1_000_000)
37
+ field :page, Integer, proc{ page > 0 }
38
+ field :isbn, proc{ isbn? }
39
+ field :lang, String, default: "en"
40
+ field :created_at, Time, create: proc{ Time.now }
41
+ field :updated_at, Time, update: proc{ Time.now }
42
+
43
+ verify :strict
44
+ verify { having?( title ) }
45
+ verify do
46
+ having?( author ) | having?( publisher )
47
+ end
48
+
49
+ def isbn?
50
+ isbn.gsub(/[\D]*/, '').size == 13
51
+ end
52
+ end
53
+
54
+
55
+ pp Book1.fields
56
+ puts
57
+
58
+ pp Book2.fields
59
+ puts
60
+
61
+ pp Book3.fields
62
+ puts
63
+
@@ -0,0 +1,26 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ Mongous.attach! :Book1
7
+ Mongous.attach! :Book2
8
+ Mongous.attach! :Book3
9
+
10
+ pp Book1.collection
11
+ pp Book2.collection
12
+ pp Book3.collection
13
+
14
+ Mongous.attach! :Book1
15
+ Mongous.attach! :Book2, :Book3
16
+
17
+ pp Book1.collection
18
+ pp Book2.collection
19
+ pp Book3.collection
20
+
21
+ Mongous.attach! :Book1, :Book2, :Book3
22
+
23
+ pp Book1.collection
24
+ pp Book2.collection
25
+ pp Book3.collection
26
+
@@ -7,10 +7,12 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
10
  p book = Book.first
12
11
  puts
13
12
 
13
+ p count = Book.count
14
+ puts
15
+
14
16
  pp books = Book.all
15
17
  puts
16
18
 
@@ -7,14 +7,16 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
+ p book = Book.where( title: /title/ ).first
11
+ puts
10
12
 
11
- p book = Book.filter( title: /title/ ).first
13
+ p count = Book.where( title: /title/ ).count
12
14
  puts
13
15
 
14
- pp books = Book.filter( title: /title/ ).all
16
+ pp books = Book.where( title: /title/ ).all
15
17
  puts
16
18
 
17
- Book.filter( title: /title/ ).each do |book|
19
+ Book.where( title: /title/ ).each do |book|
18
20
  p book
19
21
  end
20
22
  puts
@@ -7,13 +7,12 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
- Book.filter.option( projection: {_id: 0, title: 1, author: 1} ).each do |book|
10
+ Book.where.option( projection: {_id: 0, title: 1, author: 1} ).each do |book|
12
11
  p book
13
12
  end
14
13
  puts
15
14
 
16
- Book.filter( title: /title/ ).option( projection: {_id: 0, title: 1} ).each do |book|
15
+ Book.where( title: /title/ ).option( projection: {_id: 0, title: 1} ).each do |book|
17
16
  p book
18
17
  end
19
18
 
@@ -7,18 +7,17 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
- Book.filter( style: %w[A4 A5 A6] ).each do |book|
10
+ Book.where( size: %w[A4 A5 A6] ).each do |book|
12
11
  p book
13
12
  end
14
13
  puts
15
14
 
16
- Book.filter( style: %w[A4 A5]).each do |book|
15
+ Book.where( size: %w[A4 A5]).each do |book|
17
16
  p book
18
17
  end
19
18
  puts
20
19
 
21
- Book.filter( style: %w[A5] ).each do |book|
20
+ Book.where( size: %w[A5] ).each do |book|
22
21
  p book
23
22
  end
24
23
  puts
@@ -7,13 +7,12 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
- Book.filter( page: (100..300) ).each do |book|
10
+ Book.where( page: (100..300) ).each do |book|
12
11
  p book
13
12
  end
14
13
  puts
15
14
 
16
- Book.filter( page: (100...300) ).each do |book|
15
+ Book.where( page: (100...300) ).each do |book|
17
16
  p book
18
17
  end
19
18
  puts
@@ -10,11 +10,13 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price
14
15
  field :page
15
- field :publish_at
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at
19
+ field :updated_at
18
20
 
19
21
  verify :strict
20
22
  end