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"]=> false
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
- class Expected < Mongomatic::Expectations::Expectation
2
- def to_be
3
- add_error_msg unless value
4
- end
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
- def to_not_be
7
- add_error_msg if value
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
- class IsNumber < Mongomatic::Expectations::Expectation
2
- def self.name
3
- "a_number"
4
- end
1
+ module Mongomatic
2
+ module Expectations
3
+ class IsNumber < Expectation
4
+ def self.name
5
+ "a_number"
6
+ end
5
7
 
6
- def to_be
7
- return true if opts[:allow_nil] && value.nil?
8
+ def to_be
9
+ return true if opts[:allow_nil] && value.nil?
8
10
 
9
- add_error_msg if (value.to_s =~ /^\d*\.{0,1}\d+$/).nil?
10
- end
11
+ add_error_msg if (value.to_s =~ /^\d*\.{0,1}\d+$/).nil?
12
+ end
11
13
 
12
- def to_not_be
13
- add_error_msg unless (value.to_s =~ /^\d*\.{0,1}\d+$/).nil?
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
- class Match < Mongomatic::Expectations::Expectation
2
- def self.name
3
- "match"
4
- end
1
+ module Mongomatic
2
+ module Expectations
3
+ class Match < Expectation
4
+ def self.name
5
+ "match"
6
+ end
5
7
 
6
- def to_be
7
- return true if opts[:allow_nil] && value.nil?
8
+ def to_be
9
+ return true if opts[:allow_nil] && value.nil?
8
10
 
9
- add_error_msg unless opts[:with].match(value.to_s)
10
- end
11
+ add_error_msg unless opts[:with].match(value.to_s)
12
+ end
11
13
 
12
- def to_not_be
13
- add_error_msg if opts[:with].match(value.to_s)
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
- class OfLength < Mongomatic::Expectations::Expectation
2
- def self.name
3
- "of_length"
4
- end
1
+ module Mongomatic
2
+ module Expectations
3
+ class OfLength < Expectation
4
+ def self.name
5
+ "of_length"
6
+ end
5
7
 
6
- def to_be
7
- return true if opts[:allow_nil] && value.nil?
8
+ def to_be
9
+ return true if opts[:allow_nil] && value.nil?
8
10
 
9
- length = (value) ? value.size : value.to_s.size
10
- add_error_msg if opts[:minimum] && length < opts[:minimum]
11
- add_error_msg if opts[:maximum] && length > opts[:maximum]
12
- if opts[:range]
13
- add_error_msg unless opts[:range].include?(length)
14
- end
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
- class Present < Mongomatic::Expectations::Expectation
2
- def to_be
3
- add_error_msg if value.blank?
4
- end
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
- def to_not_be
7
- add_error_msg unless value.blank?
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
- - 0
9
- version: 0.3.0
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-14 00:00:00 -07:00
17
+ date: 2010-08-15 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency