remarkable_mongoid 0.1.4 → 0.2.0

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.
@@ -5,7 +5,7 @@ module Remarkable::Mongoid
5
5
  end
6
6
 
7
7
  class ValidateUniquenessOfMatcher
8
- attr_accessor :attr, :validation_type, :message
8
+ attr_accessor :attr, :validation_type, :message, :scope
9
9
 
10
10
  def initialize(attr)
11
11
  self.attr = attr.to_sym
@@ -15,18 +15,18 @@ module Remarkable::Mongoid
15
15
  self.message = message
16
16
  self
17
17
  end
18
+
19
+ def scoped_to(scope)
20
+ self.scope = scope.to_sym
21
+ self
22
+ end
18
23
 
19
24
  def matches?(subject)
20
25
  @subject = subject
21
26
  validations = @subject._validators[attr]
22
27
  if validations
23
28
  validation = validations.detect { |k| k.class == ::Mongoid::Validations::UniquenessValidator }
24
-
25
- if validation && self.message
26
- validation.options[:message] == self.message
27
- else
28
- validation != nil
29
- end
29
+ validation && check_option(validation, :message) && check_option(validation, :scope)
30
30
  else
31
31
  false
32
32
  end
@@ -40,6 +40,16 @@ module Remarkable::Mongoid
40
40
  "\nUniqueness validation failure\nExpected: '#{attr}' to be unique"
41
41
  end
42
42
 
43
+ private
44
+
45
+ def check_option(validation, option)
46
+ if self.send(option)
47
+ validation.options[option] == self.send(option)
48
+ else
49
+ true
50
+ end
51
+ end
43
52
  end
53
+
44
54
  end
45
55
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remarkable_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Cardarella
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-25 00:00:00 -04:00
18
+ date: 2010-07-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency