osu_validators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +58 -0
- data/Rakefile +17 -0
- data/lib/osu_validators.rb +9 -0
- data/lib/osu_validators/name_n_validator.rb +28 -0
- data/lib/osu_validators/osu_email_validator.rb +28 -0
- data/lib/osu_validators/osu_emplid_validator.rb +28 -0
- data/lib/osu_validators/version.rb +3 -0
- data/lib/tasks/osu_validators_tasks.rake +4 -0
- metadata +195 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dee2a43e9e8fb575f9a21d813dbd16f5d8f8a2ca19af35e7bae49f0aebf74997
|
4
|
+
data.tar.gz: a32bed696953f14b54907f9886c5bab5a9532cdafec19277b3df3c5efa95e12d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 590e2055c2b4add0a51183c27c3e131ba97ca765b390f3dcfb347e7fcea3c477cc4d28d421204d87fd6755df2a0a25c17ec7c0a9cd714362436fd3263c93c907
|
7
|
+
data.tar.gz: 167230159136d25c1c4a11f1dfaaa813e04f052a309b45da331d9bd693856d3ad6260080499adb6185ec958757343224be7180401590f928a3bbe0f3a6890d56
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Kurt Mueller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# OSU Validators
|
2
|
+
|
3
|
+
This gem contains rails `ActiveRecord` validations for a user's `emplid`, `email`, and
|
4
|
+
`name.#`.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'osu_validators'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install osu_validators
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Assuming that a `User` record has a `emplid`, `email`, and `name_n` column:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class User < ActiveRecord::Base
|
30
|
+
validates_emplid_of :emplid
|
31
|
+
validates_osu_email_of :email
|
32
|
+
validates_name_n_of :name_n
|
33
|
+
end
|
34
|
+
|
35
|
+
class User < ActiveRecord::Base
|
36
|
+
validates :emplid, emplid: true
|
37
|
+
validates :email, osu_email: true
|
38
|
+
validates :name_n, name_n: true
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
There are also validations options for each validator: `allow_nil`,
|
43
|
+
`allow_blank`, and `message`.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class User < ActiveRecord::Base
|
47
|
+
validates_emplid_of :emplid, allow_nil: true
|
48
|
+
validates :email, osu_email: { allow_blank: true }
|
49
|
+
validates :name_n, name_n: { message: "custom error message" }
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on code.osu.edu at https://code.osu.edu/asctech/osu_validators. 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.
|
56
|
+
|
57
|
+
## License
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'OsuValidators'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
# Validates that a user's name and number follows the name.# format
|
4
|
+
class NameNValidator < EachValidator
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
return if value.blank? && options[:allow_blank]
|
7
|
+
return if !!value && options[:allow_nil]
|
8
|
+
return if ::OSU::NameN.valid?(value)
|
9
|
+
|
10
|
+
error_message = options[:message] || "needs to be in the format name.#"
|
11
|
+
|
12
|
+
record.errors.add(
|
13
|
+
attribute,
|
14
|
+
:name_n,
|
15
|
+
message: error_message,
|
16
|
+
value: value
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Adds a convenience method for validating a name.#
|
22
|
+
module ClassMethods
|
23
|
+
def validates_name_n_of(*attribute_names)
|
24
|
+
validates_with NameNValidator, _merge_attributes(attribute_names)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
# Validates that a user's email follows the format of name.#@*.osu.edu
|
4
|
+
class OsuEmailValidator < EachValidator
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
return if value.blank? && options[:allow_blank]
|
7
|
+
return if !!value && options[:allow_nil]
|
8
|
+
return if ::OSU::Email.valid?(value)
|
9
|
+
|
10
|
+
error_message = options[:message] || "needs to be in the format name.#@*.osu.edu"
|
11
|
+
|
12
|
+
record.errors.add(
|
13
|
+
attribute,
|
14
|
+
:osu_email,
|
15
|
+
message: error_message,
|
16
|
+
value: value
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Adds a convenience method for validating an osu email
|
22
|
+
module ClassMethods
|
23
|
+
def validates_osu_email_of(*attribute_names)
|
24
|
+
validates_with OsuEmailValidator, _merge_attributes(attribute_names)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
# Validate's that a user's emplid is an 8-9 digit string
|
4
|
+
class EmplidValidator < EachValidator
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
return if value.blank? && options[:allow_blank]
|
7
|
+
return if !!value && options[:allow_nil]
|
8
|
+
return if ::OSU::Emplid.valid?(value)
|
9
|
+
|
10
|
+
error_message = options[:message] || "needs to be an 8-9 digit string"
|
11
|
+
|
12
|
+
record.errors.add(
|
13
|
+
attribute,
|
14
|
+
:emplid,
|
15
|
+
message: error_message,
|
16
|
+
value: value
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Adds a convenience method for validating an emplid
|
22
|
+
module ClassMethods
|
23
|
+
def validates_emplid_of(*attribute_names)
|
24
|
+
validates_with EmplidValidator, _merge_attributes(attribute_names)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osu_validators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ASCTech AppDev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: osu_person
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
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: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubycritic
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: bundler-audit
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Provides ActiveModel/ActiveRecord validators for OSU emails, name.#s,
|
154
|
+
and emplids.
|
155
|
+
email:
|
156
|
+
- appdev@asctech.osu.edu
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- MIT-LICENSE
|
162
|
+
- README.md
|
163
|
+
- Rakefile
|
164
|
+
- lib/osu_validators.rb
|
165
|
+
- lib/osu_validators/name_n_validator.rb
|
166
|
+
- lib/osu_validators/osu_email_validator.rb
|
167
|
+
- lib/osu_validators/osu_emplid_validator.rb
|
168
|
+
- lib/osu_validators/version.rb
|
169
|
+
- lib/tasks/osu_validators_tasks.rake
|
170
|
+
homepage: https://code.osu.edu/asctech/osu_validators
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata:
|
174
|
+
allowed_push_host: https://rubygems.org
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubygems_version: 3.0.3
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: Provides ActiveModel/ActiveRecord validators for OSU emails, name.#s, and
|
194
|
+
emplids.
|
195
|
+
test_files: []
|