omg_validator 0.0.8 → 1.0.0

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.
Files changed (67) hide show
  1. data/.yardoc/checksums +14 -17
  2. data/.yardoc/object_types +0 -0
  3. data/.yardoc/objects/root.dat +0 -0
  4. data/.yardoc/proxy_types +0 -0
  5. data/README.markdown +2 -7
  6. data/README.rdoc +2 -7
  7. data/doc/OmgValidator.html +31 -26
  8. data/doc/OmgValidator/Validators.html +30 -24
  9. data/doc/OmgValidator/Validators/AlphaDashValidator.html +57 -39
  10. data/doc/OmgValidator/Validators/{DecimalValidator.html → AlphaNumericDashValidator.html} +62 -43
  11. data/doc/OmgValidator/Validators/AlphaNumericValidator.html +55 -37
  12. data/doc/OmgValidator/Validators/AlphaValidator.html +55 -37
  13. data/doc/OmgValidator/Validators/EmailValidator.html +55 -37
  14. data/doc/OmgValidator/Validators/IpAddressValidator.html +55 -37
  15. data/doc/OmgValidator/Validators/PhoneNumberValidator.html +56 -38
  16. data/doc/OmgValidator/Validators/PostalCodeValidator.html +55 -37
  17. data/doc/OmgValidator/Validators/PostalOrZipCodeValidator.html +55 -37
  18. data/doc/OmgValidator/Validators/StrongPasswordValidator.html +56 -38
  19. data/doc/OmgValidator/Validators/UrlValidator.html +56 -40
  20. data/doc/OmgValidator/Validators/ZipCodeValidator.html +55 -36
  21. data/doc/_index.html +41 -74
  22. data/doc/class_list.html +12 -6
  23. data/doc/css/full_list.css +4 -2
  24. data/doc/css/style.css +50 -44
  25. data/doc/file.README.html +32 -28
  26. data/doc/file_list.html +12 -6
  27. data/doc/frames.html +20 -5
  28. data/doc/index.html +32 -28
  29. data/doc/js/app.js +52 -43
  30. data/doc/js/full_list.js +9 -9
  31. data/doc/js/jquery.js +4 -16
  32. data/doc/method_list.html +25 -43
  33. data/doc/top-level-namespace.html +25 -18
  34. data/lib/omg_validator.rb +1 -4
  35. data/lib/omg_validator/validators/alpha_dash_validator.rb +10 -6
  36. data/lib/omg_validator/validators/alpha_numeric_dash_validator.rb +25 -0
  37. data/lib/omg_validator/validators/alpha_numeric_validator.rb +8 -4
  38. data/lib/omg_validator/validators/alpha_validator.rb +7 -3
  39. data/lib/omg_validator/validators/email_validator.rb +7 -3
  40. data/lib/omg_validator/validators/ip_address_validator.rb +7 -3
  41. data/lib/omg_validator/validators/phone_number_validator.rb +7 -3
  42. data/lib/omg_validator/validators/postal_code_validator.rb +7 -3
  43. data/lib/omg_validator/validators/postal_or_zip_code_validator.rb +7 -3
  44. data/lib/omg_validator/validators/strong_password_validator.rb +7 -3
  45. data/lib/omg_validator/validators/url_validator.rb +7 -3
  46. data/lib/omg_validator/validators/zip_code_validator.rb +7 -3
  47. data/lib/omg_validator/version.rb +1 -1
  48. data/omg_validator-0.0.7.gem +0 -0
  49. data/omg_validator-0.0.8.gem +0 -0
  50. data/test/alpha_dash_validator_test.rb +26 -0
  51. data/test/alpha_numeric_dash_validator_test.rb +26 -0
  52. data/test/alpha_numeric_validator_test.rb +26 -0
  53. data/test/alpha_validator_test.rb +26 -0
  54. data/test/dummy/app/models/thing.rb +4 -10
  55. data/test/email_validator_test.rb +26 -0
  56. data/test/ip_address_validator_test.rb +26 -0
  57. data/test/support/things.rb +18 -263
  58. data/test/support/things.yml +109 -0
  59. metadata +23 -20
  60. data/doc/OmgValidator/Validators/DateValidator.html +0 -207
  61. data/doc/OmgValidator/Validators/IntegerValidator.html +0 -209
  62. data/doc/OmgValidator/Validators/NumericValidator.html +0 -208
  63. data/lib/omg_validator/validators/date_validator.rb +0 -19
  64. data/lib/omg_validator/validators/decimal_validator.rb +0 -21
  65. data/lib/omg_validator/validators/integer_validator.rb +0 -21
  66. data/lib/omg_validator/validators/numeric_validator.rb +0 -21
  67. data/test/omg_validator_test.rb +0 -247
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.7.5
9
+ &mdash; Documentation by YARD 0.8.2.1
10
10
 
11
11
  </title>
12
12
 
@@ -15,10 +15,12 @@
15
15
  <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
16
 
17
17
  <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
18
19
  relpath = '';
19
- if (relpath != '') relpath += '/';
20
+ framesUrl = "frames.html#!" + escape(window.location.href);
20
21
  </script>
21
22
 
23
+
22
24
  <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
23
25
 
24
26
  <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
@@ -26,36 +28,41 @@
26
28
 
27
29
  </head>
28
30
  <body>
29
- <script type="text/javascript" charset="utf-8">
30
- if (window.top.frames.main) document.body.className = 'frames';
31
- </script>
32
-
33
31
  <div id="header">
34
32
  <div id="menu">
35
33
 
36
- <a href="_index.html">Index</a> &raquo;
34
+ <a href="_index.html">Index</a> &raquo;
37
35
 
38
36
 
39
37
  <span class="title">Top Level Namespace</span>
40
38
 
41
-
39
+
42
40
  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
41
  </div>
44
42
 
45
43
  <div id="search">
46
44
 
47
- <a id="class_list_link" href="#">Class List</a>
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
48
49
 
49
- <a id="method_list_link" href="#">Method List</a>
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
50
54
 
51
- <a id="file_list_link" href="#">File List</a>
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
52
59
 
53
60
  </div>
54
61
  <div class="clear"></div>
55
62
  </div>
56
-
63
+
57
64
  <iframe id="search_frame"></iframe>
58
-
65
+
59
66
  <div id="content"><h1>Top Level Namespace
60
67
 
61
68
 
@@ -76,11 +83,11 @@
76
83
 
77
84
  <h2>Defined Under Namespace</h2>
78
85
  <p class="children">
79
-
86
+
80
87
 
81
88
  <strong class="modules">Modules:</strong> <span class='object_link'><a href="OmgValidator.html" title="OmgValidator (module)">OmgValidator</a></span>
82
89
 
83
-
90
+
84
91
 
85
92
 
86
93
  </p>
@@ -94,11 +101,11 @@
94
101
 
95
102
 
96
103
  </div>
97
-
104
+
98
105
  <div id="footer">
99
- Generated on Thu Apr 5 00:05:42 2012 by
106
+ Generated on Sun Sep 23 13:47:00 2012 by
100
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
101
- 0.7.5 (ruby-1.9.2).
108
+ 0.8.2.1 (ruby-1.9.3).
102
109
  </div>
103
110
 
104
111
  </body>
@@ -10,14 +10,11 @@ end
10
10
 
11
11
  require "omg_validator/validators/alpha_dash_validator"
12
12
  require "omg_validator/validators/alpha_numeric_validator"
13
+ require "omg_validator/validators/alpha_numeric_dash_validator"
13
14
  require "omg_validator/validators/alpha_validator"
14
- require "omg_validator/validators/date_validator"
15
- require "omg_validator/validators/decimal_validator"
16
15
  require "omg_validator/validators/email_validator"
17
16
  require "omg_validator/validators/url_validator"
18
17
  require "omg_validator/validators/ip_address_validator"
19
- require "omg_validator/validators/integer_validator"
20
- require "omg_validator/validators/numeric_validator"
21
18
  require "omg_validator/validators/phone_number_validator"
22
19
  require "omg_validator/validators/postal_code_validator"
23
20
  require "omg_validator/validators/postal_or_zip_code_validator"
@@ -1,17 +1,21 @@
1
1
  module OmgValidator
2
2
  module Validators
3
- # Checks whether input only contains alpha-numberic characters and dashes
3
+ # Checks whether input only contains alpha characters and dashes.
4
4
  #
5
- # validates :perma_link, alpha_dash: true
5
+ # @example
6
+ # validates :perma_link, alpha_dash: true
6
7
  #
7
- # matches: alpha-dash-23, ll2-ada, 343, Dfsdf, -,
8
- # does not match: $10.00, sub.domain, id=343, (232)
8
+ # Matches:
9
+ # hello, hello-world
10
+ #
11
+ # Does not Match:
12
+ # hello world!, hello_world
9
13
  class AlphaDashValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
12
- reg = /^([-a-z0-9_-])+$/i
16
+ reg = /^([-a-z_-])+$/i
13
17
  unless reg.match(value)
14
- record.errors[attribute] = "must contain only alpha-numeric characters and dashes"
18
+ record.errors[attribute] = "must contain only alpha characters and dashes"
15
19
  end
16
20
  end
17
21
  end
@@ -0,0 +1,25 @@
1
+ module OmgValidator
2
+ module Validators
3
+ # Checks whether input only contains alpha-numeric characters and dashes.
4
+ #
5
+ # @example
6
+ # validates :perma_link, alpha_numeric_dash: true
7
+ #
8
+ # Matches:
9
+ # alpha-num21, alpha-dash, testing, hello-world2
10
+ #
11
+ # Does not Match:
12
+ # sub.domain, alpha_score
13
+ class AlphaNumericDashValidator < ActiveModel::EachValidator
14
+ def validate_each(record, attribute, value)
15
+ return nil if value.blank?
16
+ reg = /^([-a-z0-9_-])+$/i
17
+ unless reg.match(value)
18
+ record.errors[attribute] = "must contain only alpha-numeric characters and dashes"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ ActiveModel::Validations::AlphaNumericDashValidator = OmgValidator::Validators::AlphaNumericDashValidator
@@ -1,11 +1,15 @@
1
1
  module OmgValidator
2
2
  module Validators
3
- # Checks whether input only contains alpha-numberic characters
3
+ # Checks whether input only contains alpha-numeric characters
4
4
  #
5
- # validates :title, alpha_numberic: true
5
+ # @example
6
+ # validates :title, alpha_numeric: true
6
7
  #
7
- # matches: alpha23, Testing, 343, hello,
8
- # does not match: 324-343, alpha-dash, id=343, (232)
8
+ # Matches:
9
+ # alpha23, Testing, 343, hello
10
+ #
11
+ # Does not match:
12
+ # 324-343, alpha-dash, id=343, (232)
9
13
  class AlphaNumericValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
@@ -2,10 +2,14 @@ module OmgValidator
2
2
  module Validators
3
3
  # Checks whether input only contains alphabetic characters
4
4
  #
5
- # validates :name, alpha: true
5
+ # @example
6
+ # validates :name, alpha: true
6
7
  #
7
- # matches: alpha, testing, Hello,
8
- # does not match: sub.domain, alpha-dash, id=343, (232)
8
+ # Matches:
9
+ # alpha, testing, Hello
10
+ #
11
+ # Does not Match:
12
+ # sub.domain, alpha-dash, id=343, (232)
9
13
  class AlphaValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
@@ -2,10 +2,14 @@ module OmgValidator
2
2
  module Validators
3
3
  # Checks whether input is a valid email address
4
4
  #
5
- # validates :email, email: true
5
+ # @example
6
+ # validates :email, email: true
6
7
  #
7
- # matches: email@domain.com, my_user@domain.edu.org, sub.domain@ohyeah.com,
8
- # does not match: mail@you@rock.com, domain.com
8
+ # Matches:
9
+ # email@domain.com, my_user@domain.edu.org, sub.domain@ohyeah.com
10
+ #
11
+ # Does not match:
12
+ # mail@you@rock.com, domain.com
9
13
  class EmailValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
@@ -2,10 +2,14 @@ module OmgValidator
2
2
  module Validators
3
3
  # Checks whether input is a valid IP Address
4
4
  #
5
- # validates :ip_address, ip_adress: true
5
+ # @example
6
+ # validates :ip_address, ip_adress: true
6
7
  #
7
- # matches: 101.101.102.123, 9.199.22.212, 255.255.255.0, 127.0.0.1
8
- # does not match: 101.101.102.565, 255.256.256.0, 90.0.0, 12.12.54.34.123
8
+ # Matches:
9
+ # 101.101.102.123, 9.199.22.212, 255.255.255.0, 127.0.0.1
10
+ #
11
+ # Does not match:
12
+ # 101.101.102.565, 255.256.256.0, 90.0.0, 12.12.54.34.123
9
13
  class IpAddressValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
@@ -3,10 +3,14 @@ module OmgValidator
3
3
  # Checks whether input is a valid phone number
4
4
  # Currently only supports American and Canadian formats
5
5
  #
6
- # validates :phone, phone_number: true
6
+ # @example
7
+ # validates :phone, phone_number: true
7
8
  #
8
- # matches: 2342343423, 1-800-232-1232, 100-232-2322, 1905-232-2323,
9
- # does not match: 3434343434343, 333333333, 905-232-23239, (111) 232-2322
9
+ # Matches:
10
+ # 2342343423, 1-800-232-1232, 100-232-2322, 1905-232-2323
11
+ #
12
+ # Does not match:
13
+ # 3434343434343, 333333333, 905-232-23239, (111) 232-2322
10
14
  class PhoneNumberValidator < ActiveModel::EachValidator
11
15
  def validate_each(record, attribute, value)
12
16
  return nil if value.blank?
@@ -2,10 +2,14 @@ module OmgValidator
2
2
  module Validators
3
3
  # Checks whether input is a valid postal code
4
4
  #
5
- # validates :postal_code, postal_code: true
5
+ # @example
6
+ # validates :postal_code, postal_code: true
6
7
  #
7
- # matches: L2J 4T5, l2a 9d1, h2o 4g1, h2o4g1
8
- # does not match: z2n 1n3, aan 2j2, LL2J 4T5, 5j4 f1d
8
+ # Matches:
9
+ # L2J 4T5, l2a 9d1, h2o 4g1, h2o4g1
10
+ #
11
+ # Does not match:
12
+ # z2n 1n3, aan 2j2, LL2J 4T5, 5j4 f1d
9
13
  class PostalCodeValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
@@ -2,10 +2,14 @@ module OmgValidator
2
2
  module Validators
3
3
  # Checks whether input is a valid postal code or a valid zip code
4
4
  #
5
- # validates :zip_code, postal_or_zip_code: true
5
+ # @example
6
+ # validates :zip_code, postal_or_zip_code: true
6
7
  #
7
- # matches: L2J 4T5, l2a 9d1, h2o 4g1, h2o4g1, 90210, 20037-8001, 12345
8
- # does not match: z2n 1n3, aan 2j2, LL2J 4T5, 123456, 20037-001, 207-01
8
+ # Matches:
9
+ # L2J 4T5, l2a 9d1, h2o 4g1, h2o4g1, 90210, 20037-8001, 12345
10
+ #
11
+ # Does not match:
12
+ # z2n 1n3, aan 2j2, LL2J 4T5, 123456, 20037-001, 207-01
9
13
  class PostalOrZipCodeValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
@@ -3,10 +3,14 @@ module OmgValidator
3
3
  # Checks whether password input is a strong password
4
4
  # Must contain a least one number, one lower case letter and one upper case letter and must be at least 8 characters
5
5
  #
6
- # validates :password, strong_password: true
6
+ # @example
7
+ # validates :password, strong_password: true
7
8
  #
8
- # matches: ASdj3j3jsS, 8#adCje3, pwd#fdJa9, To34zNbsr30,
9
- # does not match: password, sdfsdfs3, Jsdsdsdj, G3hn$h
9
+ # Matches:
10
+ # ASdj3j3jsS, 8#adCje3, pwd#fdJa9, To34zNbsr30,
11
+ #
12
+ # Does not match:
13
+ # password, sdfsdfs3, Jsdsdsdj, G3hn$h
10
14
  class StrongPasswordValidator < ActiveModel::EachValidator
11
15
  def validate_each(record, attribute, value)
12
16
  return nil if value.blank?
@@ -3,10 +3,14 @@ module OmgValidator
3
3
  # Checks whether input is a valid URL
4
4
  # Supports the protocols: http, https and ftp
5
5
  #
6
- # validates :url, url: true
6
+ # @example
7
+ # validates :url, url: true
7
8
  #
8
- # matches: http://www.example.com, www.example.com, example.com, sub.example.com
9
- # does not match: @asd.com, domain.c, domain.asd., amasd@asd.com.a
9
+ # Matches:
10
+ # http://www.example.com, www.example.com, example.com, sub.example.com
11
+ #
12
+ # Does not match:
13
+ # @asd.com, domain.c, domain.asd., amasd@asd.com.a
10
14
  class UrlValidator < ActiveModel::EachValidator
11
15
  def validate_each(record, attribute, value)
12
16
  return nil if value.blank?
@@ -2,10 +2,14 @@ module OmgValidator
2
2
  module Validators
3
3
  # Checks whether input is a valid zip code
4
4
  #
5
- # validates :zip_code, zip_code: true
5
+ # @example
6
+ # validates :zip_code, zip_code: true
6
7
  #
7
- # matches: 90210, 20037-8001, 12345
8
- # does not match: 123456, 20037-001, 207-01
8
+ # Matches:
9
+ # 90210, 20037-8001, 12345
10
+ #
11
+ # Does not match:
12
+ # 123456, 20037-001, 207-01
9
13
  class ZipCodeValidator < ActiveModel::EachValidator
10
14
  def validate_each(record, attribute, value)
11
15
  return nil if value.blank?
@@ -1,4 +1,4 @@
1
1
  module OmgValidator
2
2
  #Version of Gem
3
- VERSION = "0.0.8"
3
+ VERSION = "1.0.0"
4
4
  end
Binary file
Binary file
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class AlphaDashValidatorTest < ActiveSupport::TestCase
4
+ def setup
5
+ @thing = Thing.new
6
+ @things = Things.new
7
+ end
8
+
9
+ def teardown
10
+ @thing = nil
11
+ end
12
+
13
+ test 'Thing should be valid if the alpha_dash attribute contains letters, numbers, dashes, or underscores.' do
14
+ @things.alpha_dash['valid'].each do |string|
15
+ @thing.alpha_dash = string.to_s
16
+ assert @thing.valid?, string.to_s << " - " << @thing.errors.full_messages.join('\n')
17
+ end
18
+ end
19
+
20
+ test 'Thing should be invalid if the alpha_dash attribute contains spaces, punctuation or special characters.' do
21
+ @things.alpha_dash['invalid'].each do |string|
22
+ @thing.alpha_dash = string.to_s
23
+ assert !@thing.valid?, string.to_s << " - " << @thing.errors.full_messages.join('\n')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class AlphaNumericDashValidator < ActiveSupport::TestCase
4
+ def setup
5
+ @thing = Thing.new
6
+ @things = Things.new
7
+ end
8
+
9
+ def teardown
10
+ @thing = nil
11
+ end
12
+
13
+ test 'Thing should be valid if alpha_numeric_dash attribute has alphanumeric characters and dashes/underscores.' do
14
+ @things.alpha_numeric_dash['valid'].each do |string|
15
+ @thing.alpha_numeric_dash = string.to_s
16
+ assert @thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
17
+ end
18
+ end
19
+
20
+ test 'Thing should be invalid if alpha_numeric_dash attribute has non-alphanumeric and dash/underscore characters.' do
21
+ @things.alpha_numeric_dash['invalid'].each do |string|
22
+ @thing.alpha_numeric_dash = string.to_s
23
+ assert !@thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class AlphaNumericValidatorTest < ActiveSupport::TestCase
4
+ def setup
5
+ @thing = Thing.new
6
+ @things = Things.new
7
+ end
8
+
9
+ def teardown
10
+ @thing = nil
11
+ end
12
+
13
+ test 'Thing should be valid if alpha_numeric attribute has alphanumeric characters.' do
14
+ @things.alpha_numeric['valid'].each do |string|
15
+ @thing.alpha_numeric = string.to_s
16
+ assert @thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
17
+ end
18
+ end
19
+
20
+ test 'Thing should be invalid if alpha_numeric attribute has non-alphanumeric characters.' do
21
+ @things.alpha_numeric['invalid'].each do |string|
22
+ @thing.alpha_numeric = string.to_s
23
+ assert !@thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
24
+ end
25
+ end
26
+ end