mongous 0.1.0

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 +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +5 -0
  6. data/README.adoc +239 -0
  7. data/README.ja.adoc +238 -0
  8. data/Rakefile +96 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/mongous.rb +11 -0
  12. data/lib/mongous/base.rb +68 -0
  13. data/lib/mongous/document.rb +159 -0
  14. data/lib/mongous/extention.rb +167 -0
  15. data/lib/mongous/filter.rb +124 -0
  16. data/lib/mongous/version.rb +3 -0
  17. data/mongous.gemspec +26 -0
  18. data/sample/connect_auto_1.rb +14 -0
  19. data/sample/connect_auto_2.rb +15 -0
  20. data/sample/connect_default_1.rb +14 -0
  21. data/sample/connect_default_2.rb +15 -0
  22. data/sample/connect_environ_1.rb +14 -0
  23. data/sample/connect_environ_2.rb +15 -0
  24. data/sample/connect_loadfile_1.rb +15 -0
  25. data/sample/connect_loadfile_2.rb +16 -0
  26. data/sample/connect_mongo.yml +15 -0
  27. data/sample/declare_compact_1.rb +27 -0
  28. data/sample/declare_label_1.rb +39 -0
  29. data/sample/declare_ndex_1.rb +41 -0
  30. data/sample/declare_ndex_2.rb +41 -0
  31. data/sample/declare_strict_1.rb +47 -0
  32. data/sample/declare_strict_2.rb +35 -0
  33. data/sample/multi_docs_1.rb +27 -0
  34. data/sample/multi_docs_2.rb +58 -0
  35. data/sample/query_basic_1.rb +18 -0
  36. data/sample/query_basic_2.rb +18 -0
  37. data/sample/query_basic_3.rb +19 -0
  38. data/sample/query_basic_4.rb +25 -0
  39. data/sample/query_basic_5.rb +39 -0
  40. data/sample/query_detail_1.rb +24 -0
  41. data/sample/query_detail_2.rb +23 -0
  42. data/sample/query_detail_3.rb +29 -0
  43. data/sample/query_limit_1.rb +44 -0
  44. data/sample/query_order_1.rb +49 -0
  45. data/sample/query_projection_1.rb +44 -0
  46. data/sample/query_raw_1.rb +33 -0
  47. data/sample/save_basic_1.rb +13 -0
  48. data/sample/save_basic_2.rb +18 -0
  49. data/sample/save_basic_3.rb +13 -0
  50. data/sample/save_detail_1.rb +34 -0
  51. data/sample/save_detail_2.rb +34 -0
  52. data/sample/save_detail_3.rb +40 -0
  53. data/sample/save_verify_1.rb +46 -0
  54. data/sample/save_verify_2.rb +28 -0
  55. data/sample/save_verify_3.rb +26 -0
  56. data/sample/save_verify_4.rb +29 -0
  57. data/sample/save_verify_5.rb +23 -0
  58. data/sample/save_verify_6.rb +23 -0
  59. data/sample/template_article.rb +5 -0
  60. data/sample/template_person.rb +12 -0
  61. data/sample/zap_basic_1.rb +11 -0
  62. data/sample/zap_basic_2.rb +11 -0
  63. data/sample/zap_basic_3.rb +11 -0
  64. metadata +147 -0
@@ -0,0 +1,44 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Label
7
+ include Mongous::Document
8
+ end
9
+
10
+
11
+ (0...10).each do |n|
12
+ if label = Label.filter( n: n ).first
13
+ label
14
+ else
15
+ Label.create( n: n, tag: [0x40 + n].pack("C") )
16
+ end
17
+ end
18
+ puts
19
+
20
+ Label.each do |label|
21
+ p label
22
+ end
23
+ puts
24
+
25
+ Label.filter.projection( tag: 1 ).each do |label|
26
+ p label
27
+ end
28
+ puts
29
+
30
+ Label.filter.projection( _id: 0, n: 1 ).each do |label|
31
+ p label
32
+ end
33
+ puts
34
+
35
+ Label.filter.select( _id: 0, n: 1, tag: 1 ).each do |label|
36
+ p label
37
+ end
38
+ puts
39
+
40
+ Label.filter( n: [0,2,4,6,8] ).select( _id: 0, n: 1, tag: 1 ).each do |label|
41
+ p label
42
+ end
43
+ puts
44
+
@@ -0,0 +1,33 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+
11
+ book = Book.collection.find.first
12
+ p book
13
+ puts
14
+
15
+ Book.collection.find.each do |book|
16
+ p book
17
+ end
18
+ puts
19
+
20
+ Book.collection.find( title: /title/ ).each do |book|
21
+ p book
22
+ end
23
+ puts
24
+
25
+ Book.collection.find( {}, { projection: {_id: 0, title: 1, author: 1} } ).each do |book|
26
+ p book
27
+ end
28
+ puts
29
+
30
+ Book.collection.find( {title: /title/}, { projection: {_id: 0, title: 1, author: 1} } ).each do |book|
31
+ p book
32
+ end
33
+
@@ -0,0 +1,13 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+
11
+ book = Book.new( title: "title basic 1", author: "Alice", style: "A4", price: 1000, page: 100 )
12
+ book.save
13
+
@@ -0,0 +1,18 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+
11
+ book = Book.new
12
+ book.title = "title basic 2"
13
+ book.author = "Bob"
14
+ book.style = "A5"
15
+ book.price = 2000
16
+ book.page = 200
17
+ book.save
18
+
@@ -0,0 +1,13 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+
11
+ doc = { title: "title basic 3", author: "Candy", style: "A6", price: 3000, page: 300 }
12
+ Book.create( **doc )
13
+
@@ -0,0 +1,34 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title
10
+ field :author
11
+ field :publisher
12
+ field :style
13
+ field :price
14
+ field :page
15
+ field :publish_at
16
+ field :isbn
17
+ field :lang
18
+
19
+ verify :strict
20
+ end
21
+
22
+
23
+ book = Book.new
24
+ book.title = "title detail 1"
25
+ book.author = "Alice"
26
+ book.publisher = "Foobar"
27
+ book.style = "A4"
28
+ book.price = 1000
29
+ book.page = 100
30
+ book.publish_at = Date.today
31
+ book.isbn = "978-3-16-148410-0"
32
+ book.lang = "en"
33
+ book.save
34
+
@@ -0,0 +1,34 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title
10
+ field :author
11
+ field :publisher
12
+ field :style
13
+ field :price, Integer
14
+ field :page, Integer
15
+ field :publish_at, Date
16
+ field :isbn
17
+ field :lang
18
+
19
+ verify :strict
20
+ end
21
+
22
+
23
+ book = Book.new
24
+ book.title = "title detail 2"
25
+ book.author = "Bob"
26
+ book.publisher = "Foobar"
27
+ book.style = "A5"
28
+ book.price = 2000
29
+ book.page = 200
30
+ book.publish_at = Date.today
31
+ book.isbn = "978-3-16-148410-0"
32
+ book.lang = "en"
33
+ book.save
34
+
@@ -0,0 +1,40 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :author
11
+ field :publisher
12
+ field :style, %w[ A4 A5 A6 ]
13
+ field :price, Integer, (0..1_000_000)
14
+ field :page, Integer, proc{ page > 0 }
15
+ field :publish_at, Date, &proc{ Date.today }
16
+ field :isbn, proc{ isbn? }
17
+ field :lang, &proc{ "ja" }
18
+
19
+ verify :strict
20
+
21
+ def isbn?
22
+ return true unless having? isbn
23
+ str = isbn.gsub(/\D*/, '')
24
+ str.size == 13
25
+ end
26
+ end
27
+
28
+
29
+ book = Book.new
30
+ book.title = "title detail 3"
31
+ book.author = "Candy"
32
+ #book.publisher = "Foobar"
33
+ book.style = "A6"
34
+ book.price = 3000
35
+ book.page = 300
36
+ #book.publish_at = Date.today
37
+ book.isbn = "978-3-16-148410-0"
38
+ #book.lang
39
+ book.save
40
+
@@ -0,0 +1,46 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, String, :must
10
+ field :author, String
11
+ field :publisher, String
12
+ field :style, String, ["A4","A5","A6"]
13
+ field :price, Integer, (0..1_000_000)
14
+ field :date, Date, &proc{ Date.today }
15
+ field :page, Integer, proc{ page > 0 }
16
+ field :isbn, String, proc{ isbn? }
17
+ field :lang, String, &proc{ "ja" }
18
+
19
+ verify :strict
20
+ verify { having?( title ) }
21
+ verify do
22
+ having?( author ) | having?( publisher )
23
+ end
24
+
25
+ def isbn?
26
+ return false if isbn.nil?
27
+ str = isbn.gsub(/\D*/, '')
28
+ str.size == 13
29
+ end
30
+ end
31
+
32
+ begin
33
+ book = Book.new
34
+ book.title = "title verify 1"
35
+ book.author = "jane doe"
36
+ book.style = "A5"
37
+ book.price = 2000
38
+ book.page = 200
39
+ book.isbn = "978-3-16-148410-0"
40
+ book.save
41
+
42
+ rescue => e
43
+ p e.message
44
+
45
+ end
46
+
@@ -0,0 +1,28 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :author
11
+ field :publisher
12
+
13
+ verify { having?( title ) }
14
+ verify do
15
+ having?( author ) | having?( publisher )
16
+ end
17
+ end
18
+
19
+ begin
20
+ book = Book.new
21
+ book.title = "title verify 2"
22
+ book.save
23
+
24
+ rescue => e
25
+ p e.message
26
+
27
+ end
28
+
@@ -0,0 +1,26 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :page, Integer, proc{ page > 1 }
11
+ field :price, Integer, proc{ (price > 0) & (price < 10_000) }
12
+
13
+ end
14
+
15
+ begin
16
+ book = Book.new
17
+ book.title = "title over price"
18
+ book.page = 200
19
+ book.price = 20000
20
+ book.save
21
+
22
+ rescue => e
23
+ p e.message
24
+
25
+ end
26
+
@@ -0,0 +1,29 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :isbn, proc{ isbn? }
11
+
12
+ def isbn?
13
+ return true unless isbn
14
+ str = isbn.gsub(/\D*/, '')
15
+ str.size == 13
16
+ end
17
+ end
18
+
19
+ begin
20
+ book = Book.new
21
+ book.title = "title isbn"
22
+ book.isbn = "978-3-16-148410-00"
23
+ book.save
24
+
25
+ rescue => e
26
+ p e.message
27
+
28
+ end
29
+
@@ -0,0 +1,23 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :style, String, ["A4","A5","A6"]
11
+ end
12
+
13
+ begin
14
+ book = Book.new
15
+ book.title = "title isbn"
16
+ book.style = "B5"
17
+ book.save
18
+
19
+ rescue => e
20
+ p e.message
21
+
22
+ end
23
+
@@ -0,0 +1,23 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :price, Integer, (0..1_000_000)
11
+ end
12
+
13
+ begin
14
+ book = Book.new
15
+ book.title = "title price"
16
+ book.price = -1
17
+ book.save
18
+
19
+ rescue => e
20
+ p e.message
21
+
22
+ end
23
+
@@ -0,0 +1,5 @@
1
+
2
+ class Article
3
+ include Mongous::Document
4
+ end
5
+
@@ -0,0 +1,12 @@
1
+
2
+ class Person
3
+ include Mongous::Document
4
+
5
+ field :fullname
6
+ field :username
7
+ field :age, Integer
8
+ field :created_at, Date, &proc{ Date.today }
9
+
10
+ verify :strict
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+ Book.delete
11
+