validation_profiler 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/validation_profiler/rules/rules.rb +0 -1
- data/lib/validation_profiler/rules/validation_rule_manager.rb +0 -1
- data/lib/validation_profiler/version.rb +1 -1
- data/lib/validation_profiler.rb +0 -1
- metadata +2 -10
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/README.md +0 -297
- data/Rakefile +0 -2
- data/validation_profiler.gemspec +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7be2894803b988aa43fe3a86cfe093e5587b6a5f
|
4
|
+
data.tar.gz: 9f66612e86d070d44f00a2ac78430cc85e08399d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b5cff7ae9c92fd45a564512a28a287d97b20a3b2f8afe3748421e4bfb4b3c2d162a68455d29ee5b90bb126f55885eb0767b85c21c89ddb4b8aa61cb80042149
|
7
|
+
data.tar.gz: 9ff70cec914fea2c6b2e1fca817783ff9bea54d0bfc98e44dd54311ff89c39732a09aa3b249f18c6835d70d89fdee3b6d582530b84c6d4ea0110f15bfc07a2de
|
data/lib/validation_profiler.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,20 +60,12 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- ".gitignore"
|
64
|
-
- ".rspec"
|
65
|
-
- CODE_OF_CONDUCT.md
|
66
|
-
- Gemfile
|
67
|
-
- LICENSE.txt
|
68
|
-
- README.md
|
69
|
-
- Rakefile
|
70
63
|
- bin/console
|
71
64
|
- bin/setup
|
72
65
|
- lib/validation_profiler.rb
|
73
66
|
- lib/validation_profiler/rules/rules.rb
|
74
67
|
- lib/validation_profiler/rules/validation_rule_manager.rb
|
75
68
|
- lib/validation_profiler/version.rb
|
76
|
-
- validation_profiler.gemspec
|
77
69
|
homepage: https://github.com/vaughanbrittonsage/validation_profiler
|
78
70
|
licenses:
|
79
71
|
- MIT
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
7
|
-
|
8
|
-
We are committed to making participation in this project a harassment-free
|
9
|
-
experience for everyone, regardless of level of experience, gender, gender
|
10
|
-
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
-
body size, race, ethnicity, age, religion, or nationality.
|
12
|
-
|
13
|
-
Examples of unacceptable behavior by participants include:
|
14
|
-
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
* Personal attacks
|
17
|
-
* Trolling or insulting/derogatory comments
|
18
|
-
* Public or private harassment
|
19
|
-
* Publishing other's private information, such as physical or electronic
|
20
|
-
addresses, without explicit permission
|
21
|
-
* Other unethical or unprofessional conduct
|
22
|
-
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
-
threatening, offensive, or harmful.
|
28
|
-
|
29
|
-
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
-
Conduct may be permanently removed from the project team.
|
33
|
-
|
34
|
-
This code of conduct applies both within project spaces and in public spaces
|
35
|
-
when an individual is representing the project or its community.
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at vaughan.britton@sage.com. All
|
39
|
-
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
incident.
|
43
|
-
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version 1.3.0, available at
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
-
|
48
|
-
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 vaughanbrittonsage
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,297 +0,0 @@
|
|
1
|
-
# ValidationProfiler
|
2
|
-
|
3
|
-
Welcome to ValidationProfiler. This is a validation framework that allows you to seperate validation logic away from your objects and into validation profiles that can be re-used and changed without affecting your objects.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'validation_profiler'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install validation_profiler
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
First you need to create a validation profile to hold the validation logic you want to apply, validation profiles must inherit from the ValidationProfile base class or another validation profile.
|
24
|
-
|
25
|
-
class SignUpValidationProfile < ValidationProfile
|
26
|
-
.....
|
27
|
-
end
|
28
|
-
|
29
|
-
Then you specify validation rules that should be checked when this profile is validated against an object.
|
30
|
-
|
31
|
-
class SignUpValidationProfile < ValidationProfile
|
32
|
-
validates :age, :min, { value: 18 }
|
33
|
-
validates :email, :email
|
34
|
-
.....
|
35
|
-
end
|
36
|
-
|
37
|
-
When specifying a validation rule you need to specify the following arguments:
|
38
|
-
|
39
|
-
- Field name
|
40
|
-
- Rule key
|
41
|
-
- Hash containing any options required for the validation rule
|
42
|
-
|
43
|
-
So if we take another look at the first validation rule we specified in the **SignUpValidationProfile** above:
|
44
|
-
|
45
|
-
Field name = :age
|
46
|
-
Rule key = :min
|
47
|
-
Attributes Hash = { value: 18 }
|
48
|
-
|
49
|
-
This validation statement will be interpreted as:
|
50
|
-
*"The field :age must have a minimum value of 18"*
|
51
|
-
|
52
|
-
To use a validation profile you need to make a call to the **ValidationManager** class, and pass the object you want to validate along with the profile you want to use for the validation:
|
53
|
-
|
54
|
-
#create the validation manager
|
55
|
-
manager = ValidationManager.new
|
56
|
-
|
57
|
-
#call the validate method and pass the object and profile
|
58
|
-
result = manager.validate(user, profile)
|
59
|
-
|
60
|
-
Calls to the validate method will return a **ValidationManagerResult** that will detail the results of the validation.
|
61
|
-
|
62
|
-
A **ValidationManagerResult** has the following attributes:
|
63
|
-
|
64
|
-
- #outcome = [Boolean] overall outcome of the validation (passed or failed)
|
65
|
-
- #errors = [Array] containing details of each field error that occurred during validation.
|
66
|
-
|
67
|
-
Each item in the errors array has the following attributes:
|
68
|
-
|
69
|
-
- #field = The name of the field that this error occurred for.
|
70
|
-
- #message = A message that describes the validation error
|
71
|
-
|
72
|
-
## Validation Rules
|
73
|
-
|
74
|
-
**RequiredValidationRule**
|
75
|
-
|
76
|
-
This rule is used to specify a field must contain a value:
|
77
|
-
|
78
|
-
validates :name, :required
|
79
|
-
|
80
|
-
Attributes:
|
81
|
-
|
82
|
-
- **:message** [String] [Optional]
|
83
|
-
This is used to allow a custom error message to be specified.
|
84
|
-
|
85
|
-
|
86
|
-
----------
|
87
|
-
|
88
|
-
|
89
|
-
**LengthValidationRule**
|
90
|
-
|
91
|
-
This rule is used to specify a [String] or [Array] must be of a certain length:
|
92
|
-
|
93
|
-
validates :name, :length, { min: 5, max: 10 }
|
94
|
-
|
95
|
-
Attributes:
|
96
|
-
|
97
|
-
- **:min** [Numeric]
|
98
|
-
This is used to specify the minimum length of the field value.
|
99
|
-
|
100
|
-
- **:max** [Numeric]
|
101
|
-
This is used to specify the maximum length of the field value.
|
102
|
-
|
103
|
-
> **:min** & **:max** can be included together or independently providing at least 1 is specified.
|
104
|
-
|
105
|
-
- **:message** [String] [Optional]
|
106
|
-
This is used to allow a custom error message to be specified.
|
107
|
-
|
108
|
-
- **:required** [Boolean] [Default=True] [Optional]
|
109
|
-
This is used to specify if this rule should only be executed when the field contains a value.
|
110
|
-
> **True** always executes, **False** only executes when the field contains a value)*
|
111
|
-
|
112
|
-
|
113
|
-
----------
|
114
|
-
|
115
|
-
**MinValidationRule**
|
116
|
-
|
117
|
-
This rule is used to specify a minimum value a [DateTime] or [Numeric] field must have.
|
118
|
-
|
119
|
-
Attributes:
|
120
|
-
|
121
|
-
- **:value** [Numeric/DateTime]
|
122
|
-
This is used to specify the minimum value of the field.
|
123
|
-
|
124
|
-
- **:message** [String] [Optional]
|
125
|
-
This is used to allow a custom error message to be specified.
|
126
|
-
|
127
|
-
- **:required** [Boolean] [Default=True] [Optional]
|
128
|
-
This is used to specify if this rule should only be executed when the field contains a value.
|
129
|
-
> **True** always executes, **False** only executes when the field contains a value)*
|
130
|
-
|
131
|
-
----------
|
132
|
-
|
133
|
-
**MaxValidationRule**
|
134
|
-
|
135
|
-
This rule is used to specify a maximum value a [DateTime] or [Numeric] field must have.
|
136
|
-
|
137
|
-
Attributes:
|
138
|
-
|
139
|
-
- **:value** [Numeric/DateTime]
|
140
|
-
This is used to specify the maximum value of the field.
|
141
|
-
|
142
|
-
- **:message** [String] [Optional]
|
143
|
-
This is used to allow a custom error message to be specified.
|
144
|
-
|
145
|
-
- **:required** [Boolean] [Default=True] [Optional]
|
146
|
-
This is used to specify if this rule should only be executed the field contains a value.
|
147
|
-
> **True** always executes, **False** only executes when the field contains a value)*
|
148
|
-
|
149
|
-
----------
|
150
|
-
|
151
|
-
**EmailValidationRule**
|
152
|
-
|
153
|
-
This rule is used to specify a field value must contain a valid email address.
|
154
|
-
|
155
|
-
Attributes:
|
156
|
-
|
157
|
-
- **:message** [String] [Optional]
|
158
|
-
This is used to allow a custom error message to be specified.
|
159
|
-
|
160
|
-
- **:required** [Boolean] [Default=True] [Optional]
|
161
|
-
This is used to specify if this rule should only be executed when the field contains a value.
|
162
|
-
> **True** always executes, **False** only executes when the field contains a value)*
|
163
|
-
|
164
|
-
----------
|
165
|
-
|
166
|
-
**RegexValidationRule**
|
167
|
-
|
168
|
-
This rule is used to specify a regex pattern that a field value must validate against.
|
169
|
-
|
170
|
-
Attributes:
|
171
|
-
|
172
|
-
- **:regex** [Regex]
|
173
|
-
This is used to specify the regex pattern.
|
174
|
-
|
175
|
-
- **:message** [String] [Optional]
|
176
|
-
This is used to allow a custom error message to be specified.
|
177
|
-
|
178
|
-
- **:required** [Boolean] [Default=True] [Optional]
|
179
|
-
This is used to specify if this rule should only be executed when the field contains a value.
|
180
|
-
> **True** always executes, **False** only executes when the field contains a value)*
|
181
|
-
|
182
|
-
----------
|
183
|
-
|
184
|
-
**MatchValidationRule**
|
185
|
-
|
186
|
-
This rule is used to specify a field value must match the value of another field.
|
187
|
-
|
188
|
-
Attributes:
|
189
|
-
|
190
|
-
- **:field** [Symbol]
|
191
|
-
This is used to specify the name of the other field this field's value must match.
|
192
|
-
|
193
|
-
- **:message** [String] [Optional]
|
194
|
-
This is used to allow a custom error message to be specified.
|
195
|
-
|
196
|
-
- **:required** [Boolean] [Default=True] [Optional]
|
197
|
-
This is used to specify if this rule should only be executed when the field contains a value.
|
198
|
-
> **True** always executes, **False** only executes when the field contains a value)
|
199
|
-
|
200
|
-
----------
|
201
|
-
|
202
|
-
**ConditionValidationRule**
|
203
|
-
|
204
|
-
This rule is used to specify a condition statement.
|
205
|
-
|
206
|
-
e.g.
|
207
|
-
|
208
|
-
> format:
|
209
|
-
>
|
210
|
-
> When [:condition_field] [:condition_expression] [:condition_value] then [:field] [:field_expression] [:field_value]
|
211
|
-
>
|
212
|
-
>could be read as:
|
213
|
-
>
|
214
|
-
> When :age >= 18 then :accept == true
|
215
|
-
|
216
|
-
Attributes:
|
217
|
-
|
218
|
-
- **:condition_field** [Symbol]
|
219
|
-
This is used to specify the name of the condition field.
|
220
|
-
|
221
|
-
- **:condition_expression** [String]
|
222
|
-
This is used to specify the expression to use between the condition_field and the condition_value.
|
223
|
-
|
224
|
-
> **Supported expression types:**
|
225
|
-
> '=='
|
226
|
-
> '>'
|
227
|
-
> '>='
|
228
|
-
> '<'
|
229
|
-
> '<='
|
230
|
-
> '!='
|
231
|
-
|
232
|
-
|
233
|
-
- **:condition_value** [String/Numeric/DateTime/nil]
|
234
|
-
This is used to specify the value to use for the condition statement.
|
235
|
-
|
236
|
-
- **:field_expression** [String]
|
237
|
-
This is used to specify the expression to use between the field's value and the field_value attribute.
|
238
|
-
|
239
|
-
- **:field_value** [String/Numeric/DateTime/nil]
|
240
|
-
This is used to specify the value to use for the field statement.
|
241
|
-
|
242
|
-
- **:message** [String] [Optional]
|
243
|
-
This is used to allow a custom error message to be specified.
|
244
|
-
|
245
|
-
- **:required** [Boolean] [Default=True] [Optional]
|
246
|
-
This is used to specify if this rule should only be executed when the field contains a value.
|
247
|
-
> **True** always executes, **False** only executes when the field contains a value)
|
248
|
-
|
249
|
-
----------
|
250
|
-
|
251
|
-
##Custom Validation Rules
|
252
|
-
|
253
|
-
To create a custom validation rule you must create a class that inherits from the **ValidationRule** base class and implement the #error_message and #validate methods, see the **RequiredValidationRule** below as an example:
|
254
|
-
|
255
|
-
class RequiredValidationRule < ValidationRule
|
256
|
-
#implement this method to return the error message when
|
257
|
-
#this rule fails validation
|
258
|
-
def error_message(field, attributes = {})
|
259
|
-
#check if custom message was specified
|
260
|
-
if attributes[:message] == nil
|
261
|
-
#return default method
|
262
|
-
"#{field} is not valid"
|
263
|
-
else
|
264
|
-
#return custom message
|
265
|
-
attributes[:message]
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
def validate(obj, field, attributes = {})
|
270
|
-
#attempt to get the field value from the object
|
271
|
-
field_value = get_field_value(obj, field)
|
272
|
-
|
273
|
-
if field_value == nil
|
274
|
-
return false
|
275
|
-
end
|
276
|
-
|
277
|
-
return !field_value.empty?
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
The **ValidationRule** base class provides the *#get_field_value(obj, field)* method to cater for fetching the field value from the object to perform the validation against.
|
282
|
-
|
283
|
-
## Development
|
284
|
-
|
285
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
286
|
-
|
287
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
288
|
-
|
289
|
-
## Contributing
|
290
|
-
|
291
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/vaughanbrittonsage/validation_profiler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
292
|
-
|
293
|
-
|
294
|
-
## License
|
295
|
-
|
296
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
297
|
-
|
data/Rakefile
DELETED
data/validation_profiler.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'validation_profiler/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "validation_profiler"
|
8
|
-
spec.version = ValidationProfiler::VERSION
|
9
|
-
spec.authors = ["vaughanbrittonsage"]
|
10
|
-
spec.email = ["vaughanbritton@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = 'A Validation framework for creating validation profiles, allowing for the separation & reuse of validation logic from the object being validated.'
|
13
|
-
spec.description = 'A Validation framework for creating validation profiles, allowing for the separation & reuse of validation logic from the object being validated.'
|
14
|
-
spec.homepage = "https://github.com/vaughanbrittonsage/validation_profiler"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = "exe"
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
-
end
|