validation_scopes 0.5.1 → 0.6.3
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.
- checksums.yaml +7 -0
- data/{CHANGELOG → CHANGELOG.md} +30 -7
- data/README.md +3 -14
- data/lib/validation_scopes.rb +40 -14
- metadata +25 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 726ab29dbbcb8f87e1110acae3e202e3d38aeed84b7f19a96d804cc0f9a073a2
|
4
|
+
data.tar.gz: 0041aef843df442d2504279b469863e2b9cdb153c90283044a623c463971c01f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: beeab330cec72ab92b3f31e803b6f06cb3c529210b2d8ecdb45d47b65447cc5765ba38e5abf5e9508dfda25cddbbe0bbe14801feab1f26a9ff45b1c29c235a06
|
7
|
+
data.tar.gz: 75615bbece9ba5dd9ca5baf6f97c6f3537937cec17bf3019add182c6faad28d260554e0a2a4cdb46df149a47bc95896619793d8898213f3445e1e60c93dbda1b
|
data/{CHANGELOG → CHANGELOG.md}
RENAMED
@@ -1,33 +1,56 @@
|
|
1
|
-
|
1
|
+
# 0.6.3 - 2021-06-19
|
2
2
|
|
3
|
+
* Allow Rails 6.1 (James Adam)
|
4
|
+
|
5
|
+
# 0.6.2 - 2019-08-28
|
6
|
+
|
7
|
+
* Allow Rails 6 (James Adam)
|
8
|
+
|
9
|
+
# 0.6.1 - 2017-01-06
|
10
|
+
|
11
|
+
* Allow Rails 5 (Marc van Eyken, James Adam)
|
12
|
+
|
13
|
+
# 0.6.0 - 2015-07-14
|
14
|
+
|
15
|
+
* Add support for STI classes (Jeremy Mickelson)
|
16
|
+
* Add support for validates_associated (Jeremy Mickelson)
|
17
|
+
|
18
|
+
# 0.5.2 - 2015-06-18
|
19
|
+
|
20
|
+
* Fix Rails 4.2 deprecations and breakages (Tamás Michelberger)
|
21
|
+
* Loosen version constraints to allow Rails 4 (Ivan Tkalin)
|
22
|
+
|
23
|
+
# 0.5.1 - 2013-02-05
|
24
|
+
|
25
|
+
* Requires 1.9.2
|
3
26
|
* Fix for memory leak described at http://siliconsenthil.in/blog/2013/01/19/validation-scopes-leaks-memory/
|
4
27
|
* Cleaned up .gemspec and removed unnecessary files from distribution
|
5
28
|
* Set up Gemfile for development
|
6
29
|
* Simplified test suite to use pure minitest
|
7
30
|
|
8
|
-
|
31
|
+
# 0.4.1 - 2012-04-15
|
9
32
|
|
10
33
|
* Rails 3.1 and 3.2 compatibility
|
11
34
|
* Added the method all_scopes that return all the scopes in a model
|
12
35
|
|
13
|
-
|
36
|
+
# 0.4.0 - 2011-05-23
|
14
37
|
|
15
38
|
* Fixed problem with #model_name on proxy class (dynamic_form plugin)
|
16
39
|
* Fixed problem with scoped errors being lost by error_messages_for (dynamic_form plugin)
|
17
40
|
* Fixed Rails3 deprecation warnings
|
18
41
|
|
19
|
-
|
42
|
+
# 0.3.1 - 2011-02-24
|
20
43
|
|
21
44
|
* Added Rails3 compatibility
|
22
45
|
|
23
|
-
|
46
|
+
# 0.3.0 - 2009-01-04
|
24
47
|
|
25
48
|
* Fixed problem with DelegateClass not picking up method definitions that come after the validation_scope block.
|
26
49
|
|
27
|
-
|
50
|
+
# 0.2.0 - 2009-01-04
|
28
51
|
|
29
52
|
* Added basic unit tests using in-memory sqlite3
|
30
53
|
|
31
|
-
|
54
|
+
# 0.1.0 - 2009-01-03
|
32
55
|
|
33
56
|
* Initial release. Only tested within an app. Probably has lots of bugs. Test suite forthcoming.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Validation Scopes
|
1
|
+
# Validation Scopes 
|
2
2
|
|
3
3
|
This gem adds a simple class method `validation_scope` to ActiveRecord. This generates a new collection of
|
4
4
|
`ActiveRecord::Errors` that can be manipulated independently of the standard `errors`, `valid?` and `save` methods. The
|
@@ -68,13 +68,6 @@ For Rails 3 and Ruby 1.8.x use version 0.4.x, however **beware there is a memory
|
|
68
68
|
For Rails 2 see the 0.3.x version of the gem which is maintained on the [rails2
|
69
69
|
branch](https://github.com/gtd/validation_scopes/tree/rails2)
|
70
70
|
|
71
|
-
Why no Ruby 1.8.7 support? Because fixing the memory leak was easy in Ruby 1.9 by removing the deferred proxy class
|
72
|
-
definition, however this does not work in Ruby 1.8.7 because the ActiveRecord objects methods are not found. The
|
73
|
-
development of this was described in a [blog article about the design process](http://www.darwinweb.net/articles/80).
|
74
|
-
I didn't take the time to figure out why this started working in Ruby 1.9.x (smells like something to do with
|
75
|
-
`instance_eval`) but it does, and I have no inclination to fix issues in 1.8.x anymore. If you happen to know why
|
76
|
-
offhand though, I'd be glad to hear the reason.
|
77
|
-
|
78
71
|
|
79
72
|
## Installation
|
80
73
|
|
@@ -86,11 +79,7 @@ In your Gemfile:
|
|
86
79
|
|
87
80
|
gem 'validation_scopes'
|
88
81
|
|
89
|
-
Or
|
90
|
-
|
91
|
-
config.gem 'validation_scopes'
|
92
|
-
|
93
|
-
Outside of Rails:
|
82
|
+
Or without Bundler:
|
94
83
|
|
95
84
|
require 'validation_scopes'
|
96
85
|
|
@@ -109,4 +98,4 @@ context of a delegate class, private methods won't work as they would in standar
|
|
109
98
|
|
110
99
|
## Copyright
|
111
100
|
|
112
|
-
Copyright (c) 2010-
|
101
|
+
Copyright (c) 2010-2021 Gabe da Silveira. See LICENSE for details.
|
data/lib/validation_scopes.rb
CHANGED
@@ -6,23 +6,41 @@ module ValidationScopes
|
|
6
6
|
base.extend ClassMethods
|
7
7
|
end
|
8
8
|
|
9
|
+
# Based on AssociatedValidator from ActiveRecord, see:
|
10
|
+
# activerecord-4.2.0/lib/active_record/validations/associated.rb @ line 3
|
11
|
+
class AssociatedValidator < ActiveModel::EachValidator
|
12
|
+
def validate_each(record, attribute, value)
|
13
|
+
all_valid = Array.wrap(value).all? do |r|
|
14
|
+
r.marked_for_destruction? || r.send("no_#{options[:scope]}?")
|
15
|
+
end
|
16
|
+
unless all_valid
|
17
|
+
record.errors.add(attribute, 'is invalid')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
9
22
|
module ClassMethods
|
10
|
-
def
|
11
|
-
@
|
12
|
-
|
23
|
+
def validation_scopes
|
24
|
+
@validation_scopes ||= []
|
25
|
+
end
|
13
26
|
|
14
|
-
|
15
|
-
|
16
|
-
|
27
|
+
def validation_proxies
|
28
|
+
@validation_proxies ||= {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def validation_scope(scope)
|
32
|
+
validation_scopes << scope
|
17
33
|
|
18
34
|
base_class = self
|
19
35
|
|
20
|
-
|
36
|
+
superclass = self.superclass.validation_proxies[scope] || DelegateClass(base_class)
|
37
|
+
proxy_class = Class.new(superclass) do
|
21
38
|
include ActiveModel::Validations
|
22
39
|
|
23
|
-
|
24
|
-
|
25
|
-
|
40
|
+
@scope = scope
|
41
|
+
def self.validates_associated(*attr_names)
|
42
|
+
validates_with AssociatedValidator,
|
43
|
+
_merge_attributes(attr_names).reverse_merge(scope: @scope)
|
26
44
|
end
|
27
45
|
|
28
46
|
# Hacks to support dynamic_model helpers
|
@@ -30,14 +48,22 @@ module ValidationScopes
|
|
30
48
|
self
|
31
49
|
end
|
32
50
|
|
33
|
-
# Rails 3 default implementation of model_name blows up for anonymous classes
|
34
51
|
class << self; self; end.class_eval do
|
52
|
+
# Rails 3 default implementation of model_name blows up for anonymous
|
53
|
+
# classes
|
35
54
|
define_method(:model_name) do
|
36
55
|
base_class.model_name
|
37
56
|
end
|
57
|
+
# Before Rails 4.1 callback functions were created using the class
|
58
|
+
# name, so we must name our anonymous classes.
|
59
|
+
define_method(:name) do
|
60
|
+
"#{base_class.name}#{scope.to_s.classify}ValidationProxy"
|
61
|
+
end
|
38
62
|
end
|
39
63
|
end
|
40
64
|
|
65
|
+
validation_proxies[scope] = proxy_class
|
66
|
+
|
41
67
|
yield proxy_class
|
42
68
|
|
43
69
|
define_method(scope) do
|
@@ -53,14 +79,14 @@ module ValidationScopes
|
|
53
79
|
end
|
54
80
|
|
55
81
|
define_method("init_validation_scope_for_#{scope}") do
|
56
|
-
unless instance_variable_defined?("
|
57
|
-
instance_variable_set("
|
82
|
+
unless instance_variable_defined?("@validation_#{scope}")
|
83
|
+
instance_variable_set("@validation_#{scope}", proxy_class.new(self))
|
58
84
|
end
|
59
85
|
end
|
60
86
|
|
61
87
|
define_method("validation_scope_proxy_for_#{scope}") do
|
62
88
|
send "init_validation_scope_for_#{scope}"
|
63
|
-
instance_variable_get("
|
89
|
+
instance_variable_get("@validation_#{scope}")
|
64
90
|
end
|
65
91
|
end
|
66
92
|
end
|
metadata
CHANGED
@@ -1,62 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gabe da Silveira
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-06-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3
|
19
|
+
version: '3'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.2'
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3'
|
30
|
+
- - "<"
|
28
31
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
32
|
+
version: '6.2'
|
30
33
|
- !ruby/object:Gem::Dependency
|
31
34
|
name: rake
|
32
35
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
36
|
requirements:
|
35
|
-
- -
|
37
|
+
- - ">="
|
36
38
|
- !ruby/object:Gem::Version
|
37
39
|
version: '0'
|
38
40
|
type: :development
|
39
41
|
prerelease: false
|
40
42
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
43
|
requirements:
|
43
|
-
- -
|
44
|
+
- - ">="
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: '0'
|
46
47
|
- !ruby/object:Gem::Dependency
|
47
48
|
name: sqlite3
|
48
49
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
57
|
requirements:
|
59
|
-
- -
|
58
|
+
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '0'
|
62
61
|
description: Define additional sets of validations beyond the standard "errors" that
|
@@ -70,33 +69,31 @@ extra_rdoc_files:
|
|
70
69
|
- LICENSE
|
71
70
|
- README.md
|
72
71
|
files:
|
73
|
-
- CHANGELOG
|
72
|
+
- CHANGELOG.md
|
74
73
|
- LICENSE
|
75
74
|
- README.md
|
76
75
|
- lib/validation_scopes.rb
|
77
76
|
homepage: http://github.com/gtd/validation_scopes
|
78
77
|
licenses: []
|
79
|
-
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
80
|
rdoc_options: []
|
81
81
|
require_paths:
|
82
82
|
- lib
|
83
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
84
|
requirements:
|
86
|
-
- -
|
85
|
+
- - ">="
|
87
86
|
- !ruby/object:Gem::Version
|
88
87
|
version: 1.9.2
|
89
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
89
|
requirements:
|
92
|
-
- -
|
90
|
+
- - ">="
|
93
91
|
- !ruby/object:Gem::Version
|
94
92
|
version: '0'
|
95
93
|
requirements: []
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
specification_version: 3
|
94
|
+
rubygems_version: 3.0.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
100
97
|
summary: Create sets of validations independent of the life-cycle of an ActiveRecord
|
101
98
|
object
|
102
99
|
test_files: []
|