mongomatic 0.3.0 → 0.3.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.
data/README.rdoc
CHANGED
@@ -122,10 +122,11 @@ To make writing your validate method a little simpler you can use Mongomatic::Ex
|
|
122
122
|
p['name'] = 'Jordan'
|
123
123
|
p.valid?
|
124
124
|
=> true
|
125
|
+
p['name'] = nil
|
125
126
|
p['nickname'] = 'Jordan'
|
126
127
|
p.valid?
|
127
128
|
p.errors.full_messages
|
128
|
-
=> ["Name cannot be blank", "Nickname cannot contain an uppercase letter"]
|
129
|
+
=> ["Name cannot be blank", "Nickname cannot contain an uppercase letter"]
|
129
130
|
|
130
131
|
You can use any of these expectations inside of the expectations block:
|
131
132
|
|
@@ -1,9 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Mongomatic
|
2
|
+
module Expectations
|
3
|
+
class Expected < Expectation
|
4
|
+
def self.name
|
5
|
+
"expected"
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_be
|
9
|
+
add_error_msg unless value
|
10
|
+
end
|
5
11
|
|
6
|
-
|
7
|
-
|
12
|
+
def to_not_be
|
13
|
+
add_error_msg if value
|
14
|
+
end
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Mongomatic
|
2
|
+
module Expectations
|
3
|
+
class IsNumber < Expectation
|
4
|
+
def self.name
|
5
|
+
"a_number"
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
def to_be
|
9
|
+
return true if opts[:allow_nil] && value.nil?
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
add_error_msg if (value.to_s =~ /^\d*\.{0,1}\d+$/).nil?
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
def to_not_be
|
15
|
+
add_error_msg unless (value.to_s =~ /^\d*\.{0,1}\d+$/).nil?
|
16
|
+
end
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
19
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Mongomatic
|
2
|
+
module Expectations
|
3
|
+
class Match < Expectation
|
4
|
+
def self.name
|
5
|
+
"match"
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
def to_be
|
9
|
+
return true if opts[:allow_nil] && value.nil?
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
add_error_msg unless opts[:with].match(value.to_s)
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
def to_not_be
|
15
|
+
add_error_msg if opts[:with].match(value.to_s)
|
16
|
+
end
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
@@ -1,16 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Mongomatic
|
2
|
+
module Expectations
|
3
|
+
class OfLength < Expectation
|
4
|
+
def self.name
|
5
|
+
"of_length"
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
def to_be
|
9
|
+
return true if opts[:allow_nil] && value.nil?
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
length = (value) ? value.size : value.to_s.size
|
12
|
+
add_error_msg if opts[:minimum] && length < opts[:minimum]
|
13
|
+
add_error_msg if opts[:maximum] && length > opts[:maximum]
|
14
|
+
if opts[:range]
|
15
|
+
add_error_msg unless opts[:range].include?(length)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
15
19
|
end
|
16
|
-
end
|
20
|
+
end
|
@@ -1,9 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Mongomatic
|
2
|
+
module Expectations
|
3
|
+
class Present < Expectation
|
4
|
+
def self.name
|
5
|
+
"present"
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_be
|
9
|
+
add_error_msg if value.blank?
|
10
|
+
end
|
5
11
|
|
6
|
-
|
7
|
-
|
12
|
+
def to_not_be
|
13
|
+
add_error_msg unless value.blank?
|
14
|
+
end
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ben Myles
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-15 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|