easy_validatable 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -4
- data/lib/active_model/validations/association.rb +4 -4
- data/lib/easy_validatable/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -26,15 +26,21 @@ Or install it yourself as:
|
|
26
26
|
validates :person_id, :association => true
|
27
27
|
end
|
28
28
|
|
29
|
-
```ruby
|
30
29
|
class Task < Activerecord::Base
|
31
|
-
belongs_to :
|
30
|
+
belongs_to :owner, :class_name => 'User', :foreign_key => :user_id
|
31
|
+
|
32
|
+
validates_association_of :user_id, :association => :owner
|
33
|
+
end
|
34
|
+
|
35
|
+
class Student < Activerecord::Base
|
36
|
+
belongs_to :person
|
32
37
|
|
33
|
-
|
38
|
+
validates :person_id, :association => { :blank_message => 'must be informed',
|
39
|
+
:invalid_message => 'was not found or does not exist' }
|
34
40
|
end
|
35
41
|
|
36
42
|
## TODO
|
37
|
-
* implements matchers
|
43
|
+
* implements test matchers
|
38
44
|
|
39
45
|
## Contributing
|
40
46
|
|
@@ -3,7 +3,7 @@ module ActiveModel
|
|
3
3
|
module Validations
|
4
4
|
class AssociationValidator < EachValidator
|
5
5
|
def validate_each(record, attribute, value)
|
6
|
-
association_name = options.fetch :association, "#{attribute}".
|
6
|
+
association_name = options.fetch :association, "#{attribute}".gsub(/(\w+)_id/, '\1')
|
7
7
|
association = record.send :"#{association_name}"
|
8
8
|
|
9
9
|
unless record.respond_to? "#{association_name}".to_sym
|
@@ -27,7 +27,7 @@ module ActiveModel
|
|
27
27
|
end
|
28
28
|
|
29
29
|
module HelperMethods
|
30
|
-
# Validates that the specified attributes and associations are not blank(as
|
30
|
+
# Validates that the specified attributes and associations are not blank(as
|
31
31
|
# defined by Object#blank?) . Happens by default on save. Example:
|
32
32
|
#
|
33
33
|
# class Patient < ActiveRecord::Base
|
@@ -35,7 +35,7 @@ module ActiveModel
|
|
35
35
|
# validates_association_of :person_id
|
36
36
|
# end
|
37
37
|
#
|
38
|
-
# The person_id attribute and the person association must be the object
|
38
|
+
# The person_id attribute and the person association must be the object
|
39
39
|
# and can not be blank unless presence is false.
|
40
40
|
#
|
41
41
|
# Configuration options:
|
@@ -54,7 +54,7 @@ module ActiveModel
|
|
54
54
|
# if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
|
55
55
|
# or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
|
56
56
|
# proc or string should return or evaluate to a true or false value.
|
57
|
-
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
57
|
+
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
58
58
|
# See <tt>ActiveModel::Validation#validates!</tt> for more information.
|
59
59
|
def validates_association_of(*attr_names)
|
60
60
|
validates_with AssociationValidator, _merge_attributes(attr_names)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_validatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2012-
|
12
|
+
date: 2012-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
segments:
|
101
101
|
- 0
|
102
|
-
hash:
|
102
|
+
hash: 2614651779314200706
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
none: false
|
105
105
|
requirements:
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
segments:
|
110
110
|
- 0
|
111
|
-
hash:
|
111
|
+
hash: 2614651779314200706
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
114
|
rubygems_version: 1.8.24
|