mongous 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26e437e93bf76ff87a088329b744df4f1425d7b14c106d80edb46f12bbfde12f
4
- data.tar.gz: 4e6bb7dd48f0799ce33165629c658b174316fd9d271f4f51ae866b804607ae59
3
+ metadata.gz: dded44fdc39ecb6ff4eeb6db10183e3a940f19317062a73d85ecf4d4c6e10437
4
+ data.tar.gz: 34fa872a88fdc0aac33101465a490fb71f9132542e7f4583f86313527c532d9b
5
5
  SHA512:
6
- metadata.gz: 392818352168bf2c196c90693559f421e35fe6ed15bdaa013a9a3f651a5dbda66f2eb0f4ed38c25e28c5d77c1c7d5122d8384c8de56bb701b896ffe2133b3ef0
7
- data.tar.gz: 401266df4545a41f3b8d5e090f986dc2cd8215b48d153da195b8c276316a3e9ebed07b8a24e5dd677cc469d9676415a30ffb844f29211064c3d1fefa4c6badd5
6
+ metadata.gz: 1b39238447cf6419f663b22563930a5e32671983e29395bfc31dabeaf77d1dfca3ff7dbd84e54b8e231c9f8810729c2701d491b7ae9e3e8171eda400a97bf041
7
+ data.tar.gz: 7660804d5e3452714dbcbe0ac30a532789dbc553f3e5929ec58d4f0dfafd4bb9bd4dc0cb8aa124265c9af6dd6ac25acfc1361b4fa239317fc2a5bde26eb2e932
@@ -5,9 +5,12 @@ Yet another mongo wrapper library.
5
5
  == Features
6
6
 
7
7
  * A light library that depends only on the mongo driver and bson, except for built-in and standard attachments.
8
- * Item default value can be described in the block.
9
- * Item constraints can be described by Array, Range, and Proc.
10
- * Checks that constraints are met when saving and setting values.
8
+ * Document item constraints can be described in Array, Range, Regexp, Proc instances, or base classes.
9
+ * Check if the constraint conditions are met when saving the document.
10
+ * Check if the constraint condition is satisfied when setting the item value of the document.
11
+ * The contents of undefined items in the document can be described by value or Proc.
12
+ * Item settings can be described in values or Proc when creating a document.
13
+ * Item settings can be described in values or Proc when updating the document.
11
14
 
12
15
  == Installation
13
16
 
@@ -57,13 +60,14 @@ class Book
57
60
  field :title, String, :must
58
61
  field :author, String
59
62
  field :publisher, String
60
- field :style, String, ["A4","B5","A5","B6"]
61
- field :price, Integer, (0..1_000_000)
62
- field :page, Integer, proc{ page % 4 == 0 }
63
- field :isbn, String, proc{ isbn? }
64
- field :lang, String, default: "en"
65
- field :created_at, Time, create: proc{ Time.now }
66
- field :updated_at, Time, update: proc{ Time.now }
63
+ field :style, String, %w[hardcover, softcover, paperback]
64
+ field :size, String, /[AB]\d/
65
+ field :price, Integer, (0..1_000_000)
66
+ field :page, Integer, proc{ page % 4 == 0 }
67
+ field :isbn, String, proc{ isbn? }
68
+ field :lang, String, default: "en"
69
+ field :created_at, Time, create: proc{ Time.now }
70
+ field :updated_at, Time, update: proc{ Time.now }
67
71
 
68
72
  filter :foobar, {title: /foobar/}
69
73
 
@@ -87,13 +91,13 @@ end
87
91
  book = Book.new
88
92
  book.title = "title 1"
89
93
  book.price = 1000
90
- book.style = "A4"
94
+ book.size = "A4"
91
95
  book.save
92
96
 
93
- book = Book.new( title: "title 2", price: 2000, style: "A5" )
97
+ book = Book.new( title: "title 2", price: 2000, size: "A5" )
94
98
  book.save
95
99
 
96
- doc = { title: "title 3", price: 3000, style: "A6" }
100
+ doc = { title: "title 3", price: 3000, size: "A6" }
97
101
  Book.create( **doc )
98
102
  ----
99
103
 
@@ -114,14 +118,14 @@ Book.where( title: /title/ ).projection( _id: 0 ).each do |book|
114
118
  p book
115
119
  end
116
120
 
117
- Book.where( price: (1..2000), style: ["A4","A5"] ).each do |book|
121
+ Book.where( price: (1..2000), size: ["A4","A5"] ).each do |book|
118
122
  p book
119
123
  end
120
124
 
121
125
  filter1 = Book.where( title: /title/ )
122
126
  filter2 = Book.where( :foobar )
123
127
  filter3 = Book.where( price: (1..2000) )
124
- filter4 = Book.where( style: ["A4","A5"] )
128
+ filter4 = Book.where( size: ["A4","A5"] )
125
129
 
126
130
  Book.not( filter1 ).each do |book|
127
131
  p book
@@ -5,9 +5,12 @@
5
5
  == 特徴
6
6
 
7
7
  * 組込みと標準添付を除いて、mongo driver と bson のみに依存する軽いライブラリである。
8
- * 項目デフォルト値をブロックで記述できる.
9
- * 項目制約条件を Array, Range, Proc で記述できる.
10
- * 保存時および値設定時に制約条件を満たすか検査する.
8
+ * ドキュメント項目の制約条件を Array, Range, Regexp, Proc インスタンスまたは基本クラスで記述できる.
9
+ * ドキュメント保存時に制約条件を満たすか検査する.
10
+ * ドキュメントの項目値設定時に制約条件を満たすか検査する.
11
+ * ドキュメントの未定義項目の内容を値または Proc で記述できる.
12
+ * ドキュメントの作成時に項目設定内容を値または Proc で記述できる.
13
+ * ドキュメントの更新時に項目設定内容を値または Proc で記述できる.
11
14
 
12
15
  == 導入
13
16
 
@@ -54,16 +57,17 @@ Mongous.connect! ["localhost:27017"], database: "test"
54
57
  class Book
55
58
  include Mongous::Document
56
59
 
57
- field :title, String, :must
60
+ field :title, String, :must
58
61
  field :author, String
59
62
  field :publisher, String
60
- field :style, String, ["A4","B5","A5","B6"]
61
- field :price, Integer, (0..1_000_000)
62
- field :page, Integer, proc{ page % 4 == 0 }
63
- field :isbn, String, proc{ isbn? }
64
- field :lang, String, default: "en"
65
- field :created_at, Time, create: proc{ Time.now }
66
- field :updated_at, Time, update: proc{ Time.now }
63
+ field :style, String, %w[hardcover, softcover, paperback]
64
+ field :size, String, /[AB]\d/
65
+ field :price, Integer, (0..1_000_000)
66
+ field :page, Integer, proc{ page % 4 == 0 }
67
+ field :isbn, String, proc{ isbn? }
68
+ field :lang, String, default: "en"
69
+ field :created_at, Time, create: proc{ Time.now }
70
+ field :updated_at, Time, update: proc{ Time.now }
67
71
 
68
72
  filter :foobar, {title: /foobar/}
69
73
 
@@ -87,13 +91,13 @@ end
87
91
  book = Book.new
88
92
  book.title = "title 1"
89
93
  book.price = 1000
90
- book.style = "A4"
94
+ book.size = "A4"
91
95
  book.save
92
96
 
93
- book = Book.new( title: "title 2", price: 2000, style: "A5" )
97
+ book = Book.new( title: "title 2", price: 2000, size: "A5" )
94
98
  book.save
95
99
 
96
- doc = { title: "title 3", price: 3000, style: "A6" }
100
+ doc = { title: "title 3", price: 3000, size: "A6" }
97
101
  Book.create( **doc )
98
102
  ----
99
103
 
@@ -114,14 +118,14 @@ Book.where( title: /title/ ).projection( _id: 0 ).each do |book|
114
118
  p book
115
119
  end
116
120
 
117
- Book.where( price: (1..2000), style: ["A4","A5"] ).each do |book|
121
+ Book.where( price: (1..2000), size: ["A4","A5"] ).each do |book|
118
122
  p book
119
123
  end
120
124
 
121
125
  filter1 = Book.where( title: /title/ )
122
126
  filter2 = Book.where( :foobar )
123
127
  filter3 = Book.where( price: (1..2000) )
124
- filter4 = Book.where( style: ["A4","A5"] )
128
+ filter4 = Book.where( size: ["A4","A5"] )
125
129
 
126
130
  Book.not( filter1 ).each do |book|
127
131
  p book
@@ -52,17 +52,25 @@ module Mongous
52
52
  else
53
53
  savemode = :update
54
54
  end
55
+
55
56
  self.class.fields.each do |label, field|
57
+ default_value = getvalue_or_callproc( field[:default] )
56
58
  _must = field[:_attrs].include?(:must)
57
59
  if @doc.has_key?(label)
58
- if _must && !having?( @doc[label] )
59
- raise Mongous::Error, "must and not having field. : #{ label }"
60
+ if !having?( @doc[label] )
61
+ if default_value
62
+ self[label] = default_value
63
+ elsif _must
64
+ raise Mongous::Error, "must but unassigned field. : #{ label }"
65
+ elsif self.class.symbols[:strict]
66
+ self[label] = nil
67
+ end
60
68
  end
61
69
  else
62
- if default_value = getvalue_or_callproc( field[:default] )
70
+ if default_value
63
71
  self[label] = default_value
64
72
  elsif _must
65
- raise Mongous::Error, "must and unassigned field. : #{ label }"
73
+ raise Mongous::Error, "must but unassigned field. : #{ label }"
66
74
  elsif self.class.symbols[:strict]
67
75
  self[label] = nil
68
76
  end
@@ -100,7 +108,7 @@ module Mongous
100
108
  label = label.to_s
101
109
 
102
110
  if self.class.symbols[:strict]
103
- if !self.class.fields.keys.include?(label)
111
+ if !(self.class.fields.keys.include?(label) || (label == "_id"))
104
112
  raise Mongous::Error, "undefined field. : #{ label }"
105
113
  end
106
114
  end
@@ -175,6 +183,10 @@ module Mongous
175
183
  if !attr.cover?( value )
176
184
  raise Mongous::Error, "out of range. : #{ label } : #{ value }"
177
185
  end
186
+ when Regexp
187
+ if !attr.match( value )
188
+ raise Mongous::Error, "unmatch regexp. : #{ label } : #{ value }"
189
+ end
178
190
  end
179
191
  end
180
192
  end
@@ -105,8 +105,8 @@ module Mongous
105
105
 
106
106
  attrs.each do |attr|
107
107
  if klass = attr.class
108
- if ![Class, Range, Array, Proc, Symbol].include?(klass)
109
- raise Mongous::Error, "field args error. : #{ attr } on #{ symbol } at #{ call_from }"
108
+ if ![Class, Range, Array, Regexp, Proc, Symbol].include?(klass)
109
+ raise Mongous::Error, "'field' arguments error. : #{ attr } on #{ symbol } at #{ call_from }"
110
110
  end
111
111
  end
112
112
  end
@@ -114,7 +114,7 @@ module Mongous
114
114
  items.each do |key, value|
115
115
  next if [:default, :create, :update].include?(key) && [Proc, String, Numeric].include?(value.class)
116
116
 
117
- raise Mongous::Error, "field opts error. : #{key} on #{ symbol } at #{ call_from }"
117
+ raise Mongous::Error, "'field' options error. : #{key} on #{ symbol } at #{ call_from }"
118
118
  end
119
119
 
120
120
  items[:_attrs] = attrs
@@ -130,6 +130,8 @@ module Mongous
130
130
  m = /(.*?):(\d+)/.match( caller()[0] )
131
131
  call_from = [ m[1], m[2] ].join(":")
132
132
  blocks[call_from] = block
133
+ else
134
+ raise Mongous::Error, "'verify' arguments error. need directives or block."
133
135
  end
134
136
  end
135
137
 
@@ -151,7 +153,7 @@ module Mongous
151
153
  else
152
154
  m = /(.*?):(\d+)/.match( caller()[0] )
153
155
  call_from = [ m[1], m[2] ].join(":")
154
- raise Mongous::Error, "filter error. : #{symbol}, #{filter_or_condition} at #{ call_from }"
156
+ raise Mongous::Error, "'filter' arguments error. : #{symbol}, #{filter_or_condition} at #{ call_from }"
155
157
  end
156
158
  end
157
159
  end
@@ -2,7 +2,8 @@
2
2
  module Mongous
3
3
  module Extention
4
4
  def count
5
- self.collection.find.count
5
+ # self.collection.find.count
6
+ self.collection.estimated_document_count
6
7
  end
7
8
 
8
9
  def first
@@ -175,7 +176,7 @@ module Mongous
175
176
 
176
177
  def do_find
177
178
  _filter = @filter
178
- _option = @option
179
+ _option = @option.dup
179
180
  _option[:projection] = @projection if @projection
180
181
  found = @klass.collection.find( _filter, _option )
181
182
  found = found.sort( @sort ) if @sort
@@ -185,7 +186,10 @@ module Mongous
185
186
  end
186
187
 
187
188
  def count
188
- _count = do_find.count
189
+ found = @klass.collection.find( @filter )
190
+ found = found.skip( @skip ) if @skip
191
+ found = found.limit( @limit ) if @limit
192
+ _count = found.count_documents
189
193
  if @skip
190
194
  if @skip > _count
191
195
  0
@@ -219,8 +223,7 @@ module Mongous
219
223
  end
220
224
 
221
225
  def delete
222
- _filter = @filter
223
- @klass.collection.delete_many( _filter )
226
+ @klass.collection.delete_many( @filter )
224
227
  end
225
228
  end
226
229
  end
@@ -1,3 +1,3 @@
1
1
  module Mongous
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -10,9 +10,10 @@ end
10
10
 
11
11
  book = Book.new
12
12
  book.title = "declare compact"
13
- book.author = "foobar"
13
+ book.author = "Alice"
14
14
  book.publisher = nil
15
- book.style = "A4"
15
+ book.style = "hardcover"
16
+ book.size = "A4"
16
17
  book.price = 100
17
18
  book.page = 100
18
19
  # book.publish_at = nil # (default)
@@ -10,6 +10,7 @@ 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
16
  field :publish_at
@@ -22,9 +23,10 @@ end
22
23
 
23
24
  book = Book.new
24
25
  book.title = "declare label"
25
- book.author = "foobar"
26
+ book.author = "Bob"
26
27
  book.publisher = nil
27
- book.style = "A5"
28
+ book.style = "softcover"
29
+ book.size = "A5"
28
30
  book.price = 200
29
31
  book.page = 200
30
32
  # book.publish_at = nil # (default)
@@ -10,6 +10,7 @@ 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
16
  field :publish_at
@@ -24,9 +25,10 @@ end
24
25
 
25
26
  book = Book.new
26
27
  book.title = "declare index 1"
27
- book.author = "foobar"
28
+ book.author = "Candy"
28
29
  book.publisher = nil
29
- book.style = "A6"
30
+ book.style = "paperback"
31
+ book.size = "A6"
30
32
  book.price = 300
31
33
  book.page = 300
32
34
  # book.publish_at = nil # (default)
@@ -10,6 +10,7 @@ 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
16
  field :publish_at
@@ -24,9 +25,10 @@ end
24
25
 
25
26
  book = Book.new
26
27
  book.title = "declare index 2"
27
- book.author = "foobar"
28
+ book.author = "Candy"
28
29
  book.publisher = nil
29
- book.style = "A6"
30
+ book.style = "paperback"
31
+ book.size = "A6"
30
32
  book.price = 300
31
33
  book.page = 300
32
34
  # book.publish_at = nil # (default)
@@ -9,13 +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
16
  field :isbn, String, proc{ isbn? }
16
17
  field :lang, String, default: "en"
17
- field :created_at, Time, create: ->(){ Time.now }
18
- field :updated_at, Time, update: ->(){ Time.now }
18
+ field :created_at, Time, create: proc{ Time.now }
19
+ field :updated_at, Time, update: proc{ Time.now }
19
20
 
20
21
  verify :strict
21
22
  verify { having?( title ) }
@@ -31,11 +32,12 @@ end
31
32
 
32
33
  book = Book.new
33
34
  book.title = "declare strict"
34
- book.author = "foobar"
35
+ book.author = "David"
35
36
  book.publisher = nil
36
- book.style = "A6"
37
- book.price = 300
38
- book.page = 300
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)
41
43
  # book.created_at = nil # (create)
@@ -9,13 +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
16
  field :isbn, String, proc{ isbn? }
16
17
  field :lang, String, default: "en"
17
- field :created_at, Time, create: ->(){ Time.now }
18
- field :updated_at, Time, update: ->(){ Time.now }
18
+ field :created_at, Time, create: proc{ Time.now }
19
+ field :updated_at, Time, update: proc{ Time.now }
19
20
 
20
21
  verify :strict
21
22
 
@@ -14,6 +14,7 @@ class Book2
14
14
  field :author
15
15
  field :publisher
16
16
  field :style
17
+ field :size
17
18
  field :price
18
19
  field :page
19
20
  field :isbn
@@ -30,13 +31,14 @@ class Book3
30
31
  field :title, :must
31
32
  field :author
32
33
  field :publisher, String, :must
33
- field :style, String, %w[A4 A5 A6]
34
+ field :style, String, %w[hardcover softcover paperback]
35
+ field :size, String, /[AB]\d/
34
36
  field :price, Integer, (0..1_000_000)
35
37
  field :page, Integer, proc{ page > 0 }
36
38
  field :isbn, proc{ isbn? }
37
39
  field :lang, String, default: "en"
38
- field :created_at, Time, create: ->(){ Time.now }
39
- field :updated_at, Time, update: ->(){ Time.now }
40
+ field :created_at, Time, create: proc{ Time.now }
41
+ field :updated_at, Time, update: proc{ Time.now }
40
42
 
41
43
  verify :strict
42
44
  verify { having?( title ) }
@@ -7,17 +7,17 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- Book.where( style: %w[A4 A5 A6] ).each do |book|
10
+ Book.where( size: %w[A4 A5 A6] ).each do |book|
11
11
  p book
12
12
  end
13
13
  puts
14
14
 
15
- Book.where( style: %w[A4 A5]).each do |book|
15
+ Book.where( size: %w[A4 A5]).each do |book|
16
16
  p book
17
17
  end
18
18
  puts
19
19
 
20
- Book.where( style: %w[A5] ).each do |book|
20
+ Book.where( size: %w[A5] ).each do |book|
21
21
  p book
22
22
  end
23
23
  puts
@@ -10,6 +10,7 @@ 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
16
  field :publish_at
@@ -10,6 +10,7 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price, Integer
14
15
  field :page, Integer
15
16
  field :publish_at, Date
@@ -9,13 +9,14 @@ class Book
9
9
  field :title, :must
10
10
  field :author
11
11
  field :publisher
12
- field :style, %w[ A4 A5 A6 ]
12
+ field :style, %w[hardcover softcover paperback]
13
+ field :size, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
15
  field :page, Integer, proc{ page > 0 }
15
16
  field :isbn, proc{ isbn? }
16
17
  field :lang, default: "en"
17
- field :created_at, Time, create: ->(){ Time.now }
18
- field :updated_at, Time, update: ->(){ Time.now }
18
+ field :created_at, Time, create: proc{ Time.now }
19
+ field :updated_at, Time, update: proc{ Time.now }
19
20
 
20
21
  verify :strict
21
22
 
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  (1..3).each do |n|
11
11
  unless Book.where( title: "complex #{n}" ).first
12
- Book.create( title: "complex #{n}", author: (0x40 + n).chr, style: "A#{n + 3}", price: n * 1000, page: n * 100 )
12
+ Book.create( title: "complex #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
13
13
  end
14
14
  end
15
15
  puts
@@ -8,12 +8,12 @@ class Book
8
8
 
9
9
  filter :title1, { title: /filter/ }
10
10
  filter :price1, { price: (2000..3000) }
11
- filter :page1, where( style: %w[A3 A4] )
11
+ filter :page1, where( size: %w[A3 A4] )
12
12
  end
13
13
 
14
14
  (1..5).each do |n|
15
15
  unless Book.where( title: "filter #{n}" ).first
16
- Book.create( title: "filter #{n}", author: (0x40 + n).chr, style: "A#{n + 3}", price: n * 1000, page: n * 100 )
16
+ Book.create( title: "filter #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
17
17
  end
18
18
  end
19
19
  puts
@@ -3,35 +3,45 @@ require "mongous"
3
3
 
4
4
  Mongous.connect!
5
5
 
6
- class Book
6
+ class Item
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- p count = Book.where.count
10
+ (0...10).each do |n|
11
+ unless Item.where( n: n ).first
12
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
13
+ end
14
+ end
15
+ puts
16
+
17
+ p count = Item.count
18
+ puts
19
+
20
+ p count = Item.where.count
11
21
  puts
12
22
 
13
- p count = Book.where[0..4].count
23
+ p count = Item.where[0..4].count
14
24
  puts
15
25
 
16
- p count = Book.where[0...4].count
26
+ p count = Item.where[0...4].count
17
27
  puts
18
28
 
19
- p count = Book.where[0, 4].count
29
+ p count = Item.where[0, 4].count
20
30
  puts
21
31
 
22
- p count = Book.where[5, 5].count
32
+ p count = Item.where[5, 5].count
23
33
  puts
24
34
 
25
- pp books = Book.where[0, 2].all
35
+ pp books = Item.where[0, 2].all
26
36
  puts
27
37
 
28
- filter = Book.where( title: /title/ )
29
- filter[0, 4].each do |book|
30
- p book
38
+ filter = Item.where
39
+ filter[0, 4].each do |item|
40
+ p item
31
41
  end
32
42
  puts
33
- filter[4, 4].each do |book|
34
- p book
43
+ filter[4, 4].each do |item|
44
+ p item
35
45
  end
36
46
  puts
37
47
 
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  (0...10).each do |n|
11
11
  unless Item.where( n: n ).first
12
- Item.create( n: n )
12
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
13
13
  end
14
14
  end
15
15
  puts
@@ -10,7 +10,7 @@ end
10
10
  book = Book.new
11
11
  book.title = "title basic 1"
12
12
  book.author = "Alice"
13
- book.style = "A4"
13
+ book.size = "A4"
14
14
  book.price = 1000
15
15
  book.page = 100
16
16
  book.save
@@ -7,6 +7,6 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- book = Book.new( title: "title basic 2", author: "Bob", style: "A5", price: 2000, page: 200 )
10
+ book = Book.new( title: "title basic 2", author: "Bob", size: "A5", price: 2000, page: 200 )
11
11
  book.save
12
12
 
@@ -7,6 +7,6 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- doc = { title: "title basic 3", author: "Candy", style: "A6", price: 3000, page: 300 }
10
+ doc = { title: "title basic 3", author: "Candy", size: "A6", price: 3000, page: 300 }
11
11
  Book.create( **doc )
12
12
 
@@ -10,6 +10,7 @@ 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
16
  field :isbn
@@ -24,7 +25,8 @@ book = Book.new
24
25
  book.title = "title detail 1"
25
26
  book.author = "Alice"
26
27
  book.publisher = "Foobar"
27
- book.style = "A4"
28
+ book.style = "hardcover"
29
+ book.size = "A4"
28
30
  book.price = 1000
29
31
  book.page = 100
30
32
  book.isbn = "978-3-16-148410-0"
@@ -10,6 +10,7 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price, Integer
14
15
  field :page, Integer
15
16
  field :isbn
@@ -24,7 +25,8 @@ book = Book.new
24
25
  book.title = "title detail 2"
25
26
  book.author = "Bob"
26
27
  book.publisher = "Foobar"
27
- book.style = "A5"
28
+ book.style = "softcover"
29
+ book.size = "A5"
28
30
  book.price = 2000
29
31
  book.page = 200
30
32
  book.isbn = "978-3-16-148410-0"
@@ -9,13 +9,14 @@ class Book
9
9
  field :title, :must
10
10
  field :author
11
11
  field :publisher
12
- field :style, %w[ A4 A5 A6 ]
12
+ field :style, %w[hardcover, softcover, paperback]
13
+ field :size, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
15
  field :page, Integer, proc{ page > 0 }
15
16
  field :isbn, proc{ isbn? }
16
17
  field :lang, default: "en"
17
- field :created_at, Time, create: ->(){ Time.now }
18
- field :updated_at, Time, update: ->(){ Time.now }
18
+ field :created_at, Time, create: proc{ Time.now }
19
+ field :updated_at, Time, update: proc{ Time.now }
19
20
 
20
21
  verify :strict
21
22
 
@@ -30,7 +31,8 @@ book = Book.new
30
31
  book.title = "title detail 3"
31
32
  book.author = "Candy"
32
33
  #book.publisher
33
- book.style = "A6"
34
+ book.style = "paperback"
35
+ book.size = "A6"
34
36
  book.price = 3000
35
37
  book.page = 300
36
38
  book.isbn = "978-3-16-148410-0"
@@ -9,7 +9,8 @@ class Book
9
9
  field :title, String, :must
10
10
  field :author, String
11
11
  field :publisher, String
12
- field :style, String, ["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 > 0 }
15
16
  field :isbn, String, proc{ isbn? }
@@ -34,7 +35,8 @@ begin
34
35
  book = Book.new
35
36
  book.title = "title verify 1"
36
37
  book.author = "jane doe"
37
- book.style = "A5"
38
+ book.style = "softcover"
39
+ book.size = "A5"
38
40
  book.price = 2000
39
41
  book.page = 200
40
42
  book.isbn = "978-3-16-148410-0"
@@ -7,13 +7,13 @@ class Book
7
7
  include Mongous::Document
8
8
 
9
9
  field :title, :must
10
- field :style, String, ["A4","A5","A6"]
10
+ field :size, String, /[AB]\d/
11
11
  end
12
12
 
13
13
  begin
14
14
  book = Book.new
15
- book.title = "title isbn"
16
- book.style = "B5"
15
+ book.title = "title size"
16
+ book.size = "C5"
17
17
  book.save
18
18
 
19
19
  rescue => e
@@ -7,13 +7,13 @@ class Book
7
7
  include Mongous::Document
8
8
 
9
9
  field :title, :must
10
- field :price, Integer, (0..1_000_000)
10
+ field :style, String, %w[hardcover softcover paperback]
11
11
  end
12
12
 
13
13
  begin
14
14
  book = Book.new
15
- book.title = "title price"
16
- book.price = -1
15
+ book.title = "title style"
16
+ book.style = "newspaper"
17
17
  book.save
18
18
 
19
19
  rescue => e
@@ -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,13 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+ Book.where( title: /title/ ).each do |book|
11
+ book.price = (book.price || 50 ) * 2
12
+ book.save
13
+ end
@@ -3,9 +3,9 @@ require "mongous"
3
3
 
4
4
  Mongous.connect!
5
5
 
6
- class Book
6
+ class Item
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- Book.where( title: "title 1" ).delete
10
+ Item.where.delete
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - arimay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -119,9 +119,10 @@ files:
119
119
  - sample/save_verify_4.rb
120
120
  - sample/save_verify_5.rb
121
121
  - sample/save_verify_6.rb
122
+ - sample/save_verify_7.rb
123
+ - sample/update_basic_1.rb
122
124
  - sample/zap_basic_1.rb
123
125
  - sample/zap_basic_2.rb
124
- - sample/zap_basic_3.rb
125
126
  homepage: https://github.com/arimay/mongous
126
127
  licenses:
127
128
  - MIT
@@ -1,11 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
9
-
10
- Book.where( title: /title/ ).delete
11
-