mongous 0.1.8 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +286 -48
  3. data/README.ja.adoc +288 -50
  4. data/lib/mongous/base.rb +45 -2
  5. data/lib/mongous/document.rb +75 -32
  6. data/lib/mongous/extention.rb +74 -55
  7. data/lib/mongous/filter.rb +316 -233
  8. data/lib/mongous/version.rb +1 -1
  9. data/mongous.gemspec +1 -1
  10. data/sample/connect_auto_0.rb +9 -0
  11. data/sample/declare_compact_1.rb +7 -9
  12. data/sample/declare_compact_2.rb +38 -0
  13. data/sample/declare_label_1.rb +10 -8
  14. data/sample/declare_ndex_1.rb +9 -7
  15. data/sample/declare_ndex_2.rb +10 -8
  16. data/sample/declare_strict_1.rb +14 -12
  17. data/sample/declare_strict_2.rb +5 -5
  18. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -2
  19. data/sample/multi_collection_2.rb +61 -0
  20. data/sample/multi_collection_3.rb +24 -0
  21. data/sample/query_basic_1.rb +8 -3
  22. data/sample/query_basic_2.rb +11 -6
  23. data/sample/query_basic_3.rb +2 -5
  24. data/sample/query_basic_4.rb +3 -6
  25. data/sample/query_basic_5.rb +2 -5
  26. data/sample/query_basic_6.rb +35 -22
  27. data/sample/query_detail_1.rb +3 -3
  28. data/sample/query_detail_2.rb +3 -3
  29. data/sample/query_detail_3.rb +5 -5
  30. data/sample/query_filter_1.rb +44 -0
  31. data/sample/query_filter_2.rb +48 -0
  32. data/sample/{query_super_1.rb → query_find_1.rb} +6 -6
  33. data/sample/query_select_1.rb +54 -0
  34. data/sample/query_skip_limit_1.rb +48 -0
  35. data/sample/query_skip_limit_2.rb +58 -0
  36. data/sample/query_sort_1.rb +43 -0
  37. data/sample/save_basic_1.rb +2 -7
  38. data/sample/save_basic_2.rb +2 -7
  39. data/sample/save_basic_3.rb +2 -7
  40. data/sample/save_detail_1.rb +7 -6
  41. data/sample/save_detail_2.rb +7 -6
  42. data/sample/save_detail_3.rb +11 -10
  43. data/sample/save_verify_1.rb +7 -6
  44. data/sample/save_verify_2.rb +0 -2
  45. data/sample/save_verify_3.rb +1 -3
  46. data/sample/save_verify_4.rb +0 -2
  47. data/sample/save_verify_5.rb +3 -5
  48. data/sample/save_verify_6.rb +3 -5
  49. data/sample/save_verify_7.rb +21 -0
  50. data/sample/update_basic_1.rb +9 -0
  51. data/sample/zap_basic_1.rb +1 -5
  52. data/sample/zap_basic_2.rb +2 -6
  53. data/sample/zap_basic_3.rb +2 -6
  54. data/sample/zbenchmark_search_1.rb +114 -0
  55. data/sample/zbenchmark_search_2.rb +114 -0
  56. data/sample/zbenchmark_search_3.rb +88 -0
  57. metadata +20 -12
  58. data/sample/multi_docs_2.rb +0 -58
  59. data/sample/query_basic_7.rb +0 -38
  60. data/sample/query_limit_1.rb +0 -44
  61. data/sample/query_order_1.rb +0 -49
  62. data/sample/query_projection_1.rb +0 -44
  63. data/sample/template_article.rb +0 -5
  64. data/sample/template_person.rb +0 -12
@@ -1,3 +1,3 @@
1
1
  module Mongous
2
- VERSION = "0.1.8"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ["arima.yasuhiro@gmail.com"]
8
8
 
9
9
  spec.summary = %q{ Mongo wrapper library. }
10
- spec.description = %q{ Yet another lightweight mongo wrapper library. }
10
+ spec.description = %q{ Yet another mongo wrapper library. }
11
11
  spec.homepage = "https://github.com/arimay/mongous"
12
12
  spec.license = "MIT"
13
13
 
@@ -0,0 +1,9 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Book
5
+
6
+ Book.each do |book|
7
+ p book
8
+ end
9
+
@@ -1,26 +1,24 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
  end
9
7
 
10
-
11
8
  book = Book.new
12
- book.title = "title compact"
13
- book.author = "foobar"
9
+ book.title = "declare compact"
10
+ book.author = "Alice"
14
11
  book.publisher = nil
15
- book.style = "A4"
12
+ book.style = "hardcover"
13
+ book.size = "A4"
16
14
  book.price = 100
17
15
  book.page = 100
18
- # book.publish_at = nil # (default)
19
- # book.isbn = "978-3-16-148410-0"
16
+ book.isbn = "978-3-16-148410-0"
20
17
  # book.lang = nil # (default)
18
+ # book.created_at = nil # (created)
19
+ # book.updated_at = nil # (updated)
21
20
  book.save
22
21
 
23
-
24
22
  Book.each do |book|
25
23
  pp book
26
24
  end
@@ -0,0 +1,38 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Book1
5
+
6
+ book = Book1.new
7
+ book.title = "book1"
8
+ book.save
9
+
10
+ book = Book1.where( title: "book1" ).first
11
+ book.author = "alice"
12
+ book.save
13
+
14
+ Book1.each do |book|
15
+ pp book
16
+ end
17
+ puts
18
+
19
+ Book1.drop
20
+
21
+
22
+ Mongous.document! :Book2, timestamp: true
23
+
24
+ book = Book2.new
25
+ book.title = "book2"
26
+ book.save
27
+
28
+ book = Book2.where( title: "book2" ).first
29
+ book.author = "bob"
30
+ book.save
31
+
32
+ Book2.each do |book|
33
+ pp book
34
+ end
35
+ puts
36
+
37
+ Book2.drop
38
+
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -10,26 +8,30 @@ class Book
10
8
  field :author
11
9
  field :publisher
12
10
  field :style
11
+ field :size
13
12
  field :price
14
13
  field :page
15
- field :publish_at
16
14
  field :isbn
17
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
18
18
 
19
19
  verify :strict
20
20
  end
21
21
 
22
22
 
23
23
  book = Book.new
24
- book.title = "title label"
25
- book.author = "foobar"
24
+ book.title = "declare label"
25
+ book.author = "Bob"
26
26
  book.publisher = nil
27
- book.style = "A5"
27
+ book.style = "softcover"
28
+ book.size = "A5"
28
29
  book.price = 200
29
30
  book.page = 200
30
- # book.publish_at = nil # (default)
31
- # book.isbn = "978-3-16-148410-0"
31
+ book.isbn = "978-3-16-148410-0"
32
32
  # book.lang = nil # (default)
33
+ # book.created_at = nil # (created)
34
+ # book.updated_at = nil # (updated)
33
35
  book.save
34
36
 
35
37
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -10,11 +8,13 @@ class Book
10
8
  field :author
11
9
  field :publisher
12
10
  field :style
11
+ field :size
13
12
  field :price
14
13
  field :page
15
- field :publish_at
16
14
  field :isbn
17
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
18
18
 
19
19
  index :title
20
20
 
@@ -23,15 +23,17 @@ end
23
23
 
24
24
 
25
25
  book = Book.new
26
- book.title = "title strict"
27
- book.author = "foobar"
26
+ book.title = "declare index 1"
27
+ book.author = "Candy"
28
28
  book.publisher = nil
29
- book.style = "A6"
29
+ book.style = "paperback"
30
+ book.size = "A6"
30
31
  book.price = 300
31
32
  book.page = 300
32
- # book.publish_at = nil # (default)
33
33
  book.isbn = "978-3-16-148410-0"
34
34
  # book.lang = nil # (default)
35
+ # book.created_at = nil # (created)
36
+ # book.updated_at = nil # (updated)
35
37
  book.save
36
38
 
37
39
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -10,28 +8,32 @@ class Book
10
8
  field :author
11
9
  field :publisher
12
10
  field :style
11
+ field :size
13
12
  field :price
14
13
  field :page
15
- field :publish_at
16
14
  field :isbn
17
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
18
18
 
19
- index :isbn, unique: true
19
+ index :isbn
20
20
 
21
21
  verify :strict
22
22
  end
23
23
 
24
24
 
25
25
  book = Book.new
26
- book.title = "title strict"
27
- book.author = "foobar"
26
+ book.title = "declare index 2"
27
+ book.author = "Candy"
28
28
  book.publisher = nil
29
- book.style = "A6"
29
+ book.style = "paperback"
30
+ book.size = "A6"
30
31
  book.price = 300
31
32
  book.page = 300
32
- # book.publish_at = nil # (default)
33
33
  book.isbn = "978-3-16-148410-0"
34
34
  # book.lang = nil # (default)
35
+ # book.created_at = nil # (created)
36
+ # book.updated_at = nil # (updated)
35
37
  book.save
36
38
 
37
39
 
@@ -1,20 +1,20 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
9
7
  field :title, String, :must
10
8
  field :author, String
11
9
  field :publisher, String
12
- field :style, String, %w[A4 A5 A6]
10
+ field :style, String, %w[hardcover softcover paperback]
11
+ field :size, String, /[AB]\d/
13
12
  field :price, Integer, (0..1_000_000)
14
13
  field :page, Integer, proc{ page % 4 == 0 }
15
- field :publish_at, Date, &proc{ Date.today }
16
14
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
15
+ field :lang, String, default: "en"
16
+ field :created_at, Time, create: proc{ Time.now }
17
+ field :updated_at, Time, update: proc{ Time.now }
18
18
 
19
19
  verify :strict
20
20
  verify { having?( title ) }
@@ -23,21 +23,23 @@ class Book
23
23
  end
24
24
 
25
25
  def isbn?
26
- isbn&.gsub(/\D*/, '')&.size == 13
26
+ isbn.gsub(/\D*/, '').size == 13
27
27
  end
28
28
  end
29
29
 
30
30
 
31
31
  book = Book.new
32
- book.title = "title strict"
33
- book.author = "foobar"
32
+ book.title = "declare strict"
33
+ book.author = "David"
34
34
  book.publisher = nil
35
- book.style = "A6"
36
- book.price = 300
37
- book.page = 300
38
- # book.publish_at = nil # (default)
35
+ book.style = "paperback"
36
+ book.size = "A7"
37
+ book.price = 400
38
+ book.page = 400
39
39
  book.isbn = "978-3-16-148410-0"
40
40
  # book.lang = nil # (default)
41
+ # book.created_at = nil # (create)
42
+ # book.updated_at = nil # (update)
41
43
  book.save
42
44
 
43
45
 
@@ -1,20 +1,20 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
9
7
  field :title, String, :must
10
8
  field :author, String
11
9
  field :publisher, String, :must
12
- field :style, String, %w[A4 A5 A6]
10
+ field :style, String, %w[hardcover softcover paperback]
11
+ field :size, String, /[AB]\d/
13
12
  field :price, Integer, (0..1_000_000)
14
13
  field :page, Integer, proc{ page % 4 == 0 }
15
- field :publish_at, Date, &proc{ Date.today }
16
14
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
15
+ field :lang, String, default: "en"
16
+ field :created_at, Time, create: proc{ Time.now }
17
+ field :updated_at, Time, update: proc{ Time.now }
18
18
 
19
19
  verify :strict
20
20
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book1
7
5
  include Mongous::Document
8
6
  end
@@ -0,0 +1,61 @@
1
+
2
+ require "mongous"
3
+
4
+ class Book1
5
+ include Mongous::Document
6
+ end
7
+
8
+ class Book2
9
+ include Mongous::Document
10
+
11
+ field :title
12
+ field :author
13
+ field :publisher
14
+ field :style
15
+ field :size
16
+ field :price
17
+ field :page
18
+ field :isbn
19
+ field :lang
20
+ field :created_at
21
+ field :updated_at
22
+
23
+ verify :strict
24
+ end
25
+
26
+ class Book3
27
+ include Mongous::Document
28
+
29
+ field :title, :must
30
+ field :author
31
+ field :publisher, String, :must
32
+ field :style, String, %w[hardcover softcover paperback]
33
+ field :size, String, /[AB]\d/
34
+ field :price, Integer, (0..1_000_000)
35
+ field :page, Integer, proc{ page > 0 }
36
+ field :isbn, proc{ isbn? }
37
+ field :lang, String, default: "en"
38
+ field :created_at, Time, create: proc{ Time.now }
39
+ field :updated_at, Time, update: proc{ Time.now }
40
+
41
+ verify :strict
42
+ verify { having?( title ) }
43
+ verify do
44
+ having?( author ) | having?( publisher )
45
+ end
46
+
47
+ def isbn?
48
+ isbn.gsub(/[\D]*/, '').size == 13
49
+ end
50
+ end
51
+
52
+
53
+ pp Book1.fields
54
+ puts
55
+
56
+ pp Book2.fields
57
+ puts
58
+
59
+ pp Book3.fields
60
+ puts
61
+
@@ -0,0 +1,24 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Book1
5
+ Mongous.document! :Book2
6
+ Mongous.document! :Book3
7
+
8
+ pp Book1.collection
9
+ pp Book2.collection
10
+ pp Book3.collection
11
+
12
+ Mongous.document! :Book1
13
+ Mongous.document! :Book2, :Book3
14
+
15
+ pp Book1.collection
16
+ pp Book2.collection
17
+ pp Book3.collection
18
+
19
+ Mongous.document! :Book1, :Book2, :Book3
20
+
21
+ pp Book1.collection
22
+ pp Book2.collection
23
+ pp Book3.collection
24
+
@@ -1,22 +1,27 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
  end
9
7
 
10
-
8
+ p "book = Book.first"
11
9
  p book = Book.first
12
10
  puts
13
11
 
12
+ p "book = Book.last"
13
+ p book = Book.last
14
+ puts
15
+
16
+ p "count = Book.count"
14
17
  p count = Book.count
15
18
  puts
16
19
 
20
+ p "books = Book.all"
17
21
  pp books = Book.all
18
22
  puts
19
23
 
24
+ p "Book.each do |book|"
20
25
  Book.each do |book|
21
26
  p book
22
27
  end