omg_validator 0.0.7 → 0.0.8

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omg_validator (0.0.7)
4
+ omg_validator (0.0.8)
5
5
  activemodel
6
6
 
7
7
  GEM
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: $10.00, sub.domain, id=343, (232)
9
9
  class AlphaDashValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^([-a-z0-9_-])+$/i
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must contain only alpha-numeric characters and dashes"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: 324-343, alpha-dash, id=343, (232)
9
9
  class AlphaNumericValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^([a-z0-9])+$/i
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must contain only alpha-numeric characters"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: sub.domain, alpha-dash, id=343, (232)
9
9
  class AlphaValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^([a-z])+$/i
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must contain only alphabetic characters"
@@ -5,7 +5,7 @@ module OmgValidator
5
5
  # validates :posting_date, date: true
6
6
  class DateValidator < ActiveModel::EachValidator
7
7
  def validate_each(record, attribute, value)
8
- return nil if value.nil?
8
+ return nil if value.blank?
9
9
  begin
10
10
  Date.parse(value)
11
11
  rescue
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: 123, 99, -23, 1,000
9
9
  class DecimalValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^[\-+]?[0-9]+\.[0-9]+$/
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid floating point number"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: mail@you@rock.com, domain.com
9
9
  class EmailValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+$/
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid email address"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: 10.50, -22.21, 1,000, ten
9
9
  class IntegerValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^[\-+]?[0-9]+$/
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid integer"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: 101.101.102.565, 255.256.256.0, 90.0.0, 12.12.54.34.123
9
9
  class IpAddressValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$\b/
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid IP address"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: six, 23.23.12, 1,000
9
9
  class NumericValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^[\-+]?[0-9]*\.?[0-9]+$/
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid number"
@@ -9,7 +9,7 @@ module OmgValidator
9
9
  # does not match: 3434343434343, 333333333, 905-232-23239, (111) 232-2322
10
10
  class PhoneNumberValidator < ActiveModel::EachValidator
11
11
  def validate_each(record, attribute, value)
12
- return nil if value.nil?
12
+ return nil if value.blank?
13
13
  reg = /^(\d[ -\.]?)?(\d{3}[ -\.]?)?\d{3}[ -\.]?\d{4}(x\d+)?$/
14
14
  unless reg.match(value)
15
15
  record.errors[attribute] = "must be a valid phone number"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: z2n 1n3, aan 2j2, LL2J 4T5, 5j4 f1d
9
9
  class PostalCodeValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/i
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid postal code"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: z2n 1n3, aan 2j2, LL2J 4T5, 123456, 20037-001, 207-01
9
9
  class PostalOrZipCodeValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/i
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid postal or zip code"
@@ -9,7 +9,7 @@ module OmgValidator
9
9
  # does not match: password, sdfsdfs3, Jsdsdsdj, G3hn$h
10
10
  class StrongPasswordValidator < ActiveModel::EachValidator
11
11
  def validate_each(record, attribute, value)
12
- return nil if value.nil?
12
+ return nil if value.blank?
13
13
  reg = /(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
14
14
  unless reg.match(value)
15
15
  record.errors[attribute] = "must contain at least a number, a lower case letter, a upper case letter and must be at least 8 characters"
@@ -9,7 +9,7 @@ module OmgValidator
9
9
  # does not match: @asd.com, domain.c, domain.asd., amasd@asd.com.a
10
10
  class UrlValidator < ActiveModel::EachValidator
11
11
  def validate_each(record, attribute, value)
12
- return nil if value.nil?
12
+ return nil if value.blank?
13
13
  reg = /^((https?):\/\/)?([a-z\d]+([\-\.][a-z\d]+)*\.[a-z]{2,6})((:(\d{1,5}))?(\/.*)?)?$/
14
14
  unless reg.match(value)
15
15
  record.errors[attribute] = "must be a valid url"
@@ -8,7 +8,7 @@ module OmgValidator
8
8
  # does not match: 123456, 20037-001, 207-01
9
9
  class ZipCodeValidator < ActiveModel::EachValidator
10
10
  def validate_each(record, attribute, value)
11
- return nil if value.nil?
11
+ return nil if value.blank?
12
12
  reg = /^\d{5}(-\d{4})?$/i
13
13
  unless reg.match(value)
14
14
  record.errors[attribute] = "must be a valid zip code"
@@ -1,4 +1,4 @@
1
1
  module OmgValidator
2
2
  #Version of Gem
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = OmgValidator::VERSION
8
8
  s.authors = ["Nickolas Kenyeres", "Michael Mottola"]
9
9
  s.email = ["nkenyeres@gmail.com", "mikemottola@gmail.com"]
10
- s.homepage = "https://github.com/llwebsol"
10
+ s.homepage = "http://llwebsol.github.com/omg_validator/"
11
11
  s.summary = %q{A bunch of Rails validators to extend ActiveModel}
12
12
  s.description = %q{A bunch of Rails validators to extend ActiveModel}
13
13
 
@@ -23,10 +23,20 @@ class Thing
23
23
  validates :date, date: true
24
24
 
25
25
  def initialize(options = {})
26
- @alpha = options[:alpha] unless options[:alpha].nil?
27
- @alpha_numeric = options[:alpha_numeric] unless options[:alpha_numeric].nil?
28
- @alpha_dash = options[:alpha_dash] unless options[:alpha_dash].nil?
29
- @zip_code = options[:zip_code] unless options[:zip_code].nil?
30
- @postal_or_zip_code = options[:postal_or_zip_code] unless options[:postal_or_zip_code].nil?
26
+ @alpha = nil
27
+ @alpha_numeric = nil
28
+ @alpha_dash = nil
29
+ @zip_code = nil
30
+ @postal_or_zip_code = nil
31
+ @postal_code = nil
32
+ @decimal = nil
33
+ @integer = nil
34
+ @numeric = nil
35
+ @email = nil
36
+ @ip_address = nil
37
+ @url = nil
38
+ @phone = nil
39
+ @password = nil
40
+ @date = nil
31
41
  end
32
42
  end
@@ -2,14 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class OmgValidatorTest < ActiveSupport::TestCase
4
4
  def setup
5
- @thing = nil
6
- @thing = Thing.new({
7
- alpha: Things.alphas[:valid].sample,
8
- alpha_numeric: Things.alpha_numerics[:valid].sample,
9
- alpha_dash: Things.alpha_dashes[:valid].sample,
10
- zip_code: Things.zip_codes[:valid].sample,
11
- postal_or_zip_code: Things.postal_codes[:valid].sample
12
- })
5
+ @thing = Thing.new
13
6
  end
14
7
 
15
8
  def teardown
@@ -43,14 +36,13 @@ class OmgValidatorTest < ActiveSupport::TestCase
43
36
  end
44
37
  end
45
38
 
46
-
47
39
  test "thing should be valid if alpha_numeric contains only alpha-numeric characters" do
48
40
  Things.alpha_numerics[:valid].each do |alpha_numeric|
49
41
  @thing.alpha_numeric = alpha_numeric
50
42
  assert @thing.valid?, "#{alpha_numeric} - #{@thing.errors.full_messages.join("\n")}"
51
43
  end
52
44
  end
53
-
45
+
54
46
  # alpha dash
55
47
  test "thing should be invalid if alpha_dash contains non-alpha-numeric-dashes characters" do
56
48
  Things.alpha_dashes[:invalid].each do |alpha_dash|
@@ -207,7 +199,7 @@ class OmgValidatorTest < ActiveSupport::TestCase
207
199
  assert !@thing.valid?, "#{url} - #{@thing.errors.full_messages.join("\n")}"
208
200
  end
209
201
  end
210
-
202
+
211
203
  # phone number
212
204
  test "thing should be valid if phone is a valid phone number" do
213
205
  Things.phone_numbers[:valid].each do |phone|
@@ -5,7 +5,9 @@ class Things
5
5
  "a",
6
6
  "aZ",
7
7
  "AZ",
8
- "az"
8
+ "az",
9
+ "",
10
+ nil
9
11
  ],
10
12
  invalid: [
11
13
  "0",
@@ -27,7 +29,9 @@ class Things
27
29
  "01-qy",
28
30
  "01_qy",
29
31
  "01001",
30
- "-----"
32
+ "-----",
33
+ "",
34
+ nil
31
35
  ],
32
36
  invalid: [
33
37
  "#",
@@ -48,7 +52,9 @@ class Things
48
52
  "AZqy",
49
53
  "AZQY",
50
54
  "AZ99",
51
- "0099"
55
+ "0099",
56
+ "",
57
+ nil
52
58
  ],
53
59
  invalid: [
54
60
  "a qy",
@@ -66,7 +72,9 @@ class Things
66
72
  valid: [
67
73
  "L2J 4T5",
68
74
  "l2j 4t5",
69
- "l2j4t5"
75
+ "l2j4t5",
76
+ "",
77
+ nil
70
78
  ],
71
79
  invalid: [
72
80
  "L2%4T5",
@@ -81,7 +89,9 @@ class Things
81
89
  {
82
90
  valid: [
83
91
  "90210",
84
- "20037-8001"
92
+ "20037-8001",
93
+ "",
94
+ nil
85
95
  ],
86
96
  invalid: [
87
97
  "9021",
@@ -99,7 +109,9 @@ class Things
99
109
  "2012-04-23",
100
110
  "04-05-2012",
101
111
  "April 4 2012",
102
- "Wednesday May 10, 2010"
112
+ "Wednesday May 10, 2010",
113
+ "",
114
+ nil
103
115
  ],
104
116
  invalid: [
105
117
  "210-09-09",
@@ -116,7 +128,9 @@ class Things
116
128
  "10.00",
117
129
  "23.23",
118
130
  "1.23",
119
- "100.00"
131
+ "100.00",
132
+ "",
133
+ nil
120
134
  ],
121
135
  invalid: [
122
136
  "20..00",
@@ -132,7 +146,9 @@ class Things
132
146
  valid: [
133
147
  "user@domain.com",
134
148
  "my_user@domain.on.ca",
135
- "mail@hoemail.net"
149
+ "mail@hoemail.net",
150
+ "",
151
+ nil
136
152
  ],
137
153
  invalid: [
138
154
  "@asd.com",
@@ -150,7 +166,9 @@ class Things
150
166
  "10",
151
167
  "23",
152
168
  "154",
153
- "134256"
169
+ "134256",
170
+ "",
171
+ nil
154
172
  ],
155
173
  invalid: [
156
174
  "20..00",
@@ -167,7 +185,9 @@ class Things
167
185
  "120.20.123.123",
168
186
  "255.255.255.0",
169
187
  "127.0.0.1",
170
- "100.1.123.254"
188
+ "100.1.123.254",
189
+ "",
190
+ nil
171
191
  ],
172
192
  invalid: [
173
193
  "2.0.0.0.0",
@@ -184,7 +204,9 @@ class Things
184
204
  "10",
185
205
  "23.23",
186
206
  "1.23",
187
- "100.00"
207
+ "100.00",
208
+ "",
209
+ nil
188
210
  ],
189
211
  invalid: [
190
212
  "20..00",
@@ -201,7 +223,9 @@ class Things
201
223
  "123-123-1240",
202
224
  "123-123-0123",
203
225
  "1905-232-2323",
204
- "1-905-232-2323"
226
+ "1-905-232-2323",
227
+ "",
228
+ nil
205
229
  ],
206
230
  invalid: [
207
231
  "1323-23-123",
@@ -219,7 +243,9 @@ class Things
219
243
  "ASdj3j3jsS",
220
244
  "8#adCje30",
221
245
  "To34zNbsr30",
222
- "pwd#fdJa9"
246
+ "pwd#fdJa9",
247
+ "",
248
+ nil
223
249
  ],
224
250
  invalid: [
225
251
  "password",
@@ -238,7 +264,9 @@ class Things
238
264
  "www.example.com",
239
265
  "example.com",
240
266
  "http://www.example.com",
241
- "sub.example.com"
267
+ "sub.example.com",
268
+ "",
269
+ nil
242
270
  ],
243
271
  invalid: [
244
272
  "@asd.com",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omg_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-05 00:00:00.000000000 Z
13
+ date: 2012-04-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -100,6 +100,7 @@ files:
100
100
  - omg_validator-0.0.6.1.gem
101
101
  - omg_validator-0.0.6.2.gem
102
102
  - omg_validator-0.0.6.gem
103
+ - omg_validator-0.0.8.gem
103
104
  - omg_validator.gemspec
104
105
  - test/dummy/Rakefile
105
106
  - test/dummy/app/assets/javascripts/application.js
@@ -136,7 +137,7 @@ files:
136
137
  - test/omg_validator_test.rb
137
138
  - test/support/things.rb
138
139
  - test/test_helper.rb
139
- homepage: https://github.com/llwebsol
140
+ homepage: http://llwebsol.github.com/omg_validator/
140
141
  licenses: []
141
142
  post_install_message:
142
143
  rdoc_options: []
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  version: '0'
157
158
  requirements: []
158
159
  rubyforge_project: omg_validator
159
- rubygems_version: 1.8.21
160
+ rubygems_version: 1.8.23
160
161
  signing_key:
161
162
  specification_version: 3
162
163
  summary: A bunch of Rails validators to extend ActiveModel