mattetti-couchrest 0.14 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module CouchRest
14
14
  end
15
15
 
16
16
  def design_doc_slug
17
- return design_doc_slug_cache if design_doc_slug_cache && design_doc_fresh
17
+ return design_doc_slug_cache if (design_doc_slug_cache && design_doc_fresh)
18
18
  funcs = []
19
19
  design_doc['views'].each do |name, view|
20
20
  funcs << "#{name}/#{view['map']}#{view['reduce']}"
@@ -43,6 +43,7 @@ require File.join(dir, 'validators', 'format_validator')
43
43
  require File.join(dir, 'validators', 'length_validator')
44
44
  require File.join(dir, 'validators', 'numeric_validator')
45
45
  require File.join(dir, 'validators', 'method_validator')
46
+ require File.join(dir, 'validators', 'confirmation_validator')
46
47
 
47
48
  module CouchRest
48
49
  module Validation
@@ -147,7 +148,7 @@ module CouchRest
147
148
  module ClassMethods
148
149
  include CouchRest::Validation::ValidatesPresent
149
150
  include CouchRest::Validation::ValidatesAbsent
150
- # include CouchRest::Validation::ValidatesIsConfirmed
151
+ include CouchRest::Validation::ValidatesIsConfirmed
151
152
  # include CouchRest::Validation::ValidatesIsPrimitive
152
153
  # include CouchRest::Validation::ValidatesIsAccepted
153
154
  include CouchRest::Validation::ValidatesFormat
@@ -0,0 +1,103 @@
1
+ # Extracted from dm-validations 0.9.10
2
+ #
3
+ # Copyright (c) 2007 Guy van den Berg
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ module CouchRest
25
+ module Validation
26
+
27
+ ##
28
+ #
29
+ # @author Guy van den Berg
30
+ # @since 0.9
31
+ class ConfirmationValidator < GenericValidator
32
+
33
+ def initialize(field_name, options = {})
34
+ super
35
+ @options = options
36
+ @field_name, @confirm_field_name = field_name, (options[:confirm] || "#{field_name}_confirmation").to_sym
37
+ @options[:allow_nil] = true unless @options.has_key?(:allow_nil)
38
+ end
39
+
40
+ def call(target)
41
+ unless valid?(target)
42
+ error_message = @options[:message] || ValidationErrors.default_error_message(:confirmation, field_name)
43
+ add_error(target, error_message, field_name)
44
+ return false
45
+ end
46
+
47
+ return true
48
+ end
49
+
50
+ def valid?(target)
51
+ field_value = target.send(field_name)
52
+ return true if @options[:allow_nil] && field_value.nil?
53
+ return false if !@options[:allow_nil] && field_value.nil?
54
+
55
+ if target.class.properties.has_property?(field_name)
56
+ return true unless target.attribute_dirty?(field_name)
57
+ end
58
+
59
+ confirm_value = target.instance_variable_get("@#{@confirm_field_name}")
60
+ field_value == confirm_value
61
+ end
62
+
63
+ end # class ConfirmationValidator
64
+
65
+ module ValidatesIsConfirmed
66
+
67
+ ##
68
+ # Validates that the given attribute is confirmed by another attribute.
69
+ # A common use case scenario is when you require a user to confirm their
70
+ # password, for which you use both password and password_confirmation
71
+ # attributes.
72
+ #
73
+ # @option :allow_nil<Boolean> true/false (default is true)
74
+ # @option :confirm<Symbol> the attribute that you want to validate
75
+ # against (default is firstattr_confirmation)
76
+ #
77
+ # @example [Usage]
78
+ #
79
+ # class Page < Hash
80
+ # include CouchRest::ExtendedModel
81
+ # include CouchRest::Validations
82
+ #
83
+ # property :password, String
84
+ # property :email, String
85
+ # attr_accessor :password_confirmation
86
+ # attr_accessor :email_repeated
87
+ #
88
+ # validates_is_confirmed :password
89
+ # validates_is_confirmed :email, :confirm => :email_repeated
90
+ #
91
+ # # a call to valid? will return false unless:
92
+ # # password == password_confirmation
93
+ # # and
94
+ # # email == email_repeated
95
+ #
96
+ def validates_is_confirmed(*fields)
97
+ opts = opts_from_validator_args(fields)
98
+ add_validator_to_context(opts, fields, CouchRest::Validation::ConfirmationValidator)
99
+ end
100
+
101
+ end # module ValidatesIsConfirmed
102
+ end # module Validation
103
+ end # module CouchRest
data/lib/couchrest.rb CHANGED
@@ -27,7 +27,7 @@ require 'couchrest/monkeypatches'
27
27
 
28
28
  # = CouchDB, close to the metal
29
29
  module CouchRest
30
- VERSION = '0.14'
30
+ VERSION = '0.14.1'
31
31
 
32
32
  autoload :Server, 'couchrest/core/server'
33
33
  autoload :Database, 'couchrest/core/database'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattetti-couchrest
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.14"
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Chris Anderson
@@ -115,6 +115,7 @@ files:
115
115
  - lib/couchrest/validation/validation_errors.rb
116
116
  - lib/couchrest/validation/validators
117
117
  - lib/couchrest/validation/validators/absent_field_validator.rb
118
+ - lib/couchrest/validation/validators/confirmation_validator.rb
118
119
  - lib/couchrest/validation/validators/format_validator.rb
119
120
  - lib/couchrest/validation/validators/formats
120
121
  - lib/couchrest/validation/validators/formats/email.rb