validate 1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,16 +34,27 @@ module Kongo
34
34
  # extensions, which are implemented differently from regular extensions.
35
35
  #
36
36
  def self.add_validation_extension(collection_name, mod)
37
- @@validations = mod.validations
38
- ((@@extensions ||= {})[collection_name.to_sym] ||= []) << mod
37
+ (@@validations ||= {})[collection_name.to_sym] = mod.validations
39
38
  end
40
39
 
41
- # This method is used by the validations library to fetch the validations
42
- # to run. Do not call this directly.
40
+ # Override initialize to also set @validator.
43
41
  #
44
- def self.validations
45
- @@validations
42
+ alias :original_initialize :initialize
43
+ def initialize(*args)
44
+ ret = original_initialize(*args)
45
+ @validator = (@@validations ||= {})[@coll.name.to_sym]
46
+ ret
46
47
  end
48
+
49
+ # Implements interface to validations via the two usual methods.
50
+ #
51
+ def validates?
52
+ @validator.validates?(self)
53
+ end
54
+ def failures
55
+ @validator.failures
56
+ end
57
+
47
58
  end
48
59
  end
49
60
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Validate
3
- VERSION = '1.2'
3
+ VERSION = '1.2.1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-30 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec