validation_skipper 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +2 -12
- data/lib/validation_skipper/version.rb +1 -1
- data/lib/validation_skipper.rb +9 -13
- data/validation_skipper.gemspec +3 -0
- metadata +49 -8
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmYxMmRhOTI5OGVlZTNlY2NmODY5Mjc5NGU5YTZhYTk4ODgwZTJjNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWJmOWJlNTQ4NzgyMzY1OTJkMGU3ODQ1ODc2ZDJkZWVkNGI0MmNjOA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTg0MzJmZGI3YmE5NjFkNzgxNDE3OTNmZDAyNjJkYjY1YTUwNzZhZjMzOThk
|
10
|
+
YzNiNDc4NTczZTQ4ZmExYmM0ZDQ5NzM3ZGI4ZDFmOTk0MTZiNGJhNmQxMjEy
|
11
|
+
NTJkNTEyM2UzNTczYzk4ZTMzYmI4MWM2MDE1MTg2ZjFjMDZhMTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2NiZjE1YzkzNTQ5NjhiMDEzNmM1N2MzYmVjNzljNjVmZTAwMmRjNjM5MDI0
|
14
|
+
MGUyNDdiMWE1Y2VhYTEzYzJjMDUzNDFmY2MyODA5YjYxOTk4MjI4ZDFmOTQ1
|
15
|
+
Y2Y2Zjk2NGFkOGQ0NjY0MzNjZmFmYjBiZmViNzhiY2U0MDdhNzE=
|
data/README.md
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
# ValidationSkipper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
For example, you may have a user model that validates name, email, password, etc., but you may want to present a view where the end-user can update his/her name in one screen, but change the password on another screen.
|
6
|
-
|
7
|
-
If the model is validating across all the attributes, you'll need a way around this.
|
8
|
-
|
9
|
-
This gem will help you easily declare which attributes to skip and when to skip them.
|
10
|
-
|
11
|
-
**WARNING:** Skipping validations is not considered best practice (albeit sometimes it is necessary), so skip them at your own risk!
|
3
|
+
This Rails gem lets you easily declare which attribute validations to skip in you models, and choose when to skip them in your controllers.
|
12
4
|
|
13
5
|
## Installation
|
14
6
|
|
@@ -49,8 +41,6 @@ Let's say you have a User model with a name, phone, and password.
|
|
49
41
|
validates :phone, :presence => true, :unless => skip_phone_validation?
|
50
42
|
validates :password, :presence => true, :unless => skip_pasword_validation?
|
51
43
|
|
52
|
-
(Basically just add `:unless => skip_<name of your attribute>_validation?` to each of your validation methods)
|
53
|
-
|
54
44
|
### In your controller:
|
55
45
|
|
56
46
|
Now just pass the names of the fields you want to skip validation for from within your controller, ex:
|
@@ -58,7 +48,7 @@ Now just pass the names of the fields you want to skip validation for from withi
|
|
58
48
|
def create
|
59
49
|
@user = User.new(params[:user])
|
60
50
|
@user.skip_validation_for :name, :phone
|
61
|
-
|
51
|
+
# The rest of your code goes here...
|
62
52
|
end
|
63
53
|
|
64
54
|
This will now skip the validations for name and phone only, but still validate for password.
|
data/lib/validation_skipper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "validation_skipper/version"
|
2
|
+
require "active_record"
|
3
|
+
|
4
|
+
module ValidationSkipper
|
2
5
|
|
3
|
-
module ValidationSkipper # Creates "attr_accessor" methods and related boolean checker method.
|
4
|
-
|
5
6
|
extend ActiveSupport::Concern
|
6
7
|
|
7
8
|
module ClassMethods
|
@@ -13,16 +14,11 @@ module ValidationSkipper # Creates "attr_accessor" methods and related boolean
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Defines a "skip_validation_for" method to use in controllers.
|
22
|
-
def skip_validation_for(*args)
|
23
|
-
args.each { |attr| send("skip_#{attr}_validation=", true) }
|
17
|
+
module InstanceMethods
|
18
|
+
def skip_validation_for(*args)
|
19
|
+
args.each { |attr| send("skip_#{attr}_validation=", true) }
|
20
|
+
end
|
24
21
|
end
|
25
22
|
end
|
26
|
-
|
27
|
-
|
28
|
-
ActiveRecord::Base.send(:include, ValidationSkipper)
|
23
|
+
ActiveRecord::Validations.send(:include, ValidationSkipper)
|
24
|
+
ActiveModel::Validations.send(:include, ValidationSkipper)
|
data/validation_skipper.gemspec
CHANGED
@@ -16,4 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
+
gem.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_runtime_dependency "activerecord"
|
19
22
|
end
|
metadata
CHANGED
@@ -1,16 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_skipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nathan Pearson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
14
55
|
description: If you need a way to easily skip validations on some attributes and only
|
15
56
|
in certain cases, this gem will allow you to do it in a clean and elegant way.
|
16
57
|
email:
|
@@ -29,26 +70,26 @@ files:
|
|
29
70
|
- validation_skipper.gemspec
|
30
71
|
homepage: https://github.com/npearson72/validation_skipper
|
31
72
|
licenses: []
|
73
|
+
metadata: {}
|
32
74
|
post_install_message:
|
33
75
|
rdoc_options: []
|
34
76
|
require_paths:
|
35
77
|
- lib
|
36
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
79
|
requirements:
|
39
80
|
- - ! '>='
|
40
81
|
- !ruby/object:Gem::Version
|
41
82
|
version: '0'
|
42
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
84
|
requirements:
|
45
85
|
- - ! '>='
|
46
86
|
- !ruby/object:Gem::Version
|
47
87
|
version: '0'
|
48
88
|
requirements: []
|
49
89
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 2.1.10
|
51
91
|
signing_key:
|
52
|
-
specification_version:
|
92
|
+
specification_version: 4
|
53
93
|
summary: Easily skip validations in Rails
|
54
94
|
test_files: []
|
95
|
+
has_rdoc:
|