whyvalidationssuckin96 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/LICENSE +20 -0
  4. data/README.md +121 -0
  5. data/Rakefile +45 -0
  6. data/VERSION +1 -0
  7. data/doc/ActiveRecord/RecordInvalid.html +258 -0
  8. data/doc/ActiveRecord.html +93 -0
  9. data/doc/FalseClass.html +87 -0
  10. data/doc/NilClass.html +87 -0
  11. data/doc/Numeric.html +87 -0
  12. data/doc/Object.html +79 -0
  13. data/doc/String.html +87 -0
  14. data/doc/TrueClass.html +87 -0
  15. data/doc/WhyValidationsSuckIn96/ActiveRecord/InstanceMethods.html +156 -0
  16. data/doc/WhyValidationsSuckIn96/ActiveRecord.html +192 -0
  17. data/doc/WhyValidationsSuckIn96/AttributeBasedValidation.html +464 -0
  18. data/doc/WhyValidationsSuckIn96/SkippableValidation.html +194 -0
  19. data/doc/WhyValidationsSuckIn96/ValidatesAcceptance.html +254 -0
  20. data/doc/WhyValidationsSuckIn96/ValidatesAssociated.html +250 -0
  21. data/doc/WhyValidationsSuckIn96/ValidatesConfirmation.html +251 -0
  22. data/doc/WhyValidationsSuckIn96/ValidatesExclusion.html +388 -0
  23. data/doc/WhyValidationsSuckIn96/ValidatesFormat.html +387 -0
  24. data/doc/WhyValidationsSuckIn96/ValidatesInclusion.html +388 -0
  25. data/doc/WhyValidationsSuckIn96/ValidatesLength.html +469 -0
  26. data/doc/WhyValidationsSuckIn96/ValidatesNumericality.html +267 -0
  27. data/doc/WhyValidationsSuckIn96/ValidatesPresence.html +244 -0
  28. data/doc/WhyValidationsSuckIn96/ValidatesUniqueness.html +289 -0
  29. data/doc/WhyValidationsSuckIn96/Validation.html +934 -0
  30. data/doc/WhyValidationsSuckIn96/ValidationBuilder.html +391 -0
  31. data/doc/WhyValidationsSuckIn96/ValidationSupport/ClassMethods.html +249 -0
  32. data/doc/WhyValidationsSuckIn96/ValidationSupport/InstanceMethods.html +484 -0
  33. data/doc/WhyValidationsSuckIn96/ValidationSupport.html +168 -0
  34. data/doc/WhyValidationsSuckIn96.html +97 -0
  35. data/doc/_index.html +346 -0
  36. data/doc/class_list.html +293 -0
  37. data/doc/css/common.css +1 -0
  38. data/doc/css/full_list.css +23 -0
  39. data/doc/css/style.css +263 -0
  40. data/doc/file.README.html +173 -0
  41. data/doc/file_list.html +29 -0
  42. data/doc/index.html +173 -0
  43. data/doc/js/app.js +91 -0
  44. data/doc/js/full_list.js +39 -0
  45. data/doc/js/jquery.js +19 -0
  46. data/doc/method_list.html +462 -0
  47. data/doc/top-level-namespace.html +81 -0
  48. data/lib/whyvalidationssuckin96/attribute_based_validation.rb +46 -0
  49. data/lib/whyvalidationssuckin96/constants.rb +3 -0
  50. data/lib/whyvalidationssuckin96/ext/blank.rb +47 -0
  51. data/lib/whyvalidationssuckin96/macros/validates_acceptance.rb +36 -0
  52. data/lib/whyvalidationssuckin96/macros/validates_associated.rb +33 -0
  53. data/lib/whyvalidationssuckin96/macros/validates_confirmation.rb +40 -0
  54. data/lib/whyvalidationssuckin96/macros/validates_exclusion.rb +38 -0
  55. data/lib/whyvalidationssuckin96/macros/validates_format.rb +38 -0
  56. data/lib/whyvalidationssuckin96/macros/validates_inclusion.rb +38 -0
  57. data/lib/whyvalidationssuckin96/macros/validates_length.rb +98 -0
  58. data/lib/whyvalidationssuckin96/macros/validates_numericality.rb +56 -0
  59. data/lib/whyvalidationssuckin96/macros/validates_presence.rb +30 -0
  60. data/lib/whyvalidationssuckin96/macros.rb +9 -0
  61. data/lib/whyvalidationssuckin96/rails/active_record.rb +94 -0
  62. data/lib/whyvalidationssuckin96/rails/macros/validates_uniqueness.rb +87 -0
  63. data/lib/whyvalidationssuckin96/rails/macros.rb +1 -0
  64. data/lib/whyvalidationssuckin96/skippable_validation.rb +59 -0
  65. data/lib/whyvalidationssuckin96/validation.rb +88 -0
  66. data/lib/whyvalidationssuckin96/validation_builder.rb +56 -0
  67. data/lib/whyvalidationssuckin96/validation_support.rb +74 -0
  68. data/lib/whyvalidationssuckin96.rb +4 -0
  69. data/test/attribute_based_validation_test.rb +58 -0
  70. data/test/macros/validates_acceptance_test.rb +64 -0
  71. data/test/macros/validates_associated_test.rb +60 -0
  72. data/test/macros/validates_confirmation_test.rb +63 -0
  73. data/test/macros/validates_exclusion_test.rb +37 -0
  74. data/test/macros/validates_format_test.rb +43 -0
  75. data/test/macros/validates_inclusion_test.rb +37 -0
  76. data/test/macros/validates_length_test.rb +179 -0
  77. data/test/macros/validates_numericality_test.rb +129 -0
  78. data/test/macros/validates_presence_test.rb +31 -0
  79. data/test/rails/active_record_test.rb +187 -0
  80. data/test/rails/active_record_test_helper.rb +90 -0
  81. data/test/rails/macros/validates_uniqueness_test.rb +153 -0
  82. data/test/skippable_validation_test.rb +102 -0
  83. data/test/teststrap.rb +4 -0
  84. data/test/validation_builder_test.rb +62 -0
  85. data/test/validation_support_test.rb +209 -0
  86. data/test/validation_test.rb +101 -0
  87. data/whyvalidationssuckin96.gemspec +153 -0
  88. metadata +189 -0
@@ -0,0 +1,173 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>Documentation by YARD 0.5.2</title>
7
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <div id="header">
20
+ <div id="menu">
21
+
22
+ <a href="_index.html" title="Index">Index</a> &raquo;
23
+ <span class="title">File: README</span>
24
+
25
+ </div>
26
+
27
+ <div id="search">
28
+ <a id="class_list_link" href="#">Namespace List</a>
29
+ <a id="method_list_link" href="#">Method List</a>
30
+ <a id ="file_list_link" href="#">File List</a>
31
+ </div>
32
+
33
+ <div class="clear"></div>
34
+ </div>
35
+
36
+ <iframe id="search_frame"></iframe>
37
+
38
+ <div id="content"><div id='filecontents'><h1 id='whyvalidationssuckin96'>WhyValidationsSuckIn96</h1>
39
+
40
+ <h2 id='description'>Description</h2>
41
+
42
+ <p>WhyValidationsSuckIn96 is a library for adding validation support to objects. It aims to have a very minimal &#8216;surface area&#8217;, API-wise, and to be as easily testable as possible. It has no external dependencies unless you wish to use the ActiveRecord integration, in which case you clearly need ActiveRecord installed.</p>
43
+
44
+ <h2 id='documentation'>Documentation</h2>
45
+
46
+ <p>See &#8216;doc/index.html&#8217; for details, or <a href='http://thumblemonks.github.com/whyvalidationssuckin96'>check the GitHub Pages site for the project</a>.</p>
47
+
48
+ <h2 id='install'>Install</h2>
49
+
50
+ <p>gem install &#8216;whyvalidationssuckin96&#8217;</p>
51
+
52
+ <h2 id='basic_usage'>Basic Usage</h2>
53
+
54
+ <p>Require &#8216;whyvalidationssuckin96&#8217; and include the WhyValidationsSuckIn96::ValidationSupport module into your class:</p>
55
+
56
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96'</span>
57
+
58
+ <span class='class class kw'>class</span> <span class='Song constant id'>Song</span>
59
+ <span class='attr_accessor identifier id'>attr_accessor</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:artist</span>
60
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidationSupport constant id'>ValidationSupport</span>
61
+ <span class='end end kw'>end</span>
62
+ </pre>
63
+
64
+ <p>Define your validations or call pre-existing validation macros inside a validation setup block:</p>
65
+
66
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96'</span>
67
+
68
+ <span class='class class kw'>class</span> <span class='Song constant id'>Song</span>
69
+ <span class='attr_accessor identifier id'>attr_accessor</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:artist</span><span class='comma token'>,</span> <span class='symbol val'>:year</span>
70
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidationSupport constant id'>ValidationSupport</span>
71
+
72
+ <span class='setup_validations identifier id'>setup_validations</span> <span class='do do kw'>do</span>
73
+ <span class='validate identifier id'>validate</span> <span class='symbol val'>:no_eighties_crap</span> <span class='do do kw'>do</span>
74
+ <span class='if if kw'>if</span> <span class='dstring node'>%w[BonJovi Dokken]</span><span class='dot token'>.</span><span class='include? fid id'>include?</span><span class='lparen token'>(</span><span class='validatable identifier id'>validatable</span><span class='dot token'>.</span><span class='artist identifier id'>artist</span><span class='rparen token'>)</span>
75
+ <span class='fail identifier id'>fail</span>
76
+ <span class='else else kw'>else</span>
77
+ <span class='pass identifier id'>pass</span>
78
+ <span class='end end kw'>end</span>
79
+ <span class='end end kw'>end</span>
80
+
81
+ <span class='validates_presence_of identifier id'>validates_presence_of</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:artist</span>
82
+ <span class='validates_numericality_of identifier id'>validates_numericality_of</span> <span class='symbol val'>:year</span>
83
+ <span class='end end kw'>end</span>
84
+ <span class='end end kw'>end</span>
85
+ </pre>
86
+
87
+ <p>Check instances of your class for validity and inspect the failed validations:</p>
88
+
89
+ <pre class="code"><span class='song identifier id'>song</span> <span class='assign token'>=</span> <span class='Song constant id'>Song</span><span class='dot token'>.</span><span class='new identifier id'>new</span>
90
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='valid? fid id'>valid?</span>
91
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='invalid? fid id'>invalid?</span>
92
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='failed_validations identifier id'>failed_validations</span>
93
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='passed_validations identifier id'>passed_validations</span>
94
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='all_validations identifier id'>all_validations</span>
95
+ </pre>
96
+
97
+ <p>Easily inspect and test for the presence of validations on your class:</p>
98
+
99
+ <pre class="code"><span class='Song constant id'>Song</span><span class='dot token'>.</span><span class='validation_collection identifier id'>validation_collection</span><span class='dot token'>.</span><span class='detect identifier id'>detect</span> <span class='do do kw'>do</span> <span class='bitor op'>|</span><span class='lparen token'>(</span><span class='klass identifier id'>klass</span><span class='comma token'>,</span> <span class='opts identifier id'>opts</span><span class='rparen token'>)</span><span class='bitor op'>|</span>
100
+ <span class='klass identifier id'>klass</span><span class='dot token'>.</span><span class='is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidatesPresence constant id'>ValidatesPresence</span><span class='rparen token'>)</span>
101
+ <span class='end end kw'>end</span>
102
+ </pre>
103
+
104
+ <p>Create your own reusable and testable validations:</p>
105
+
106
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96/skippable_validation'</span>
107
+ <span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96/attribute_based_validation'</span>
108
+
109
+ <span class='class class kw'>class</span> <span class='ValidatesPrimaryColour constant id'>ValidatesPrimaryColour</span> <span class='lt op'>&lt;</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='Validation constant id'>Validation</span>
110
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='SkippableValidation constant id'>SkippableValidation</span>
111
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='AttributeBasedValidation constant id'>AttributeBasedValidation</span>
112
+
113
+ <span class='DefaultOptions constant id'>DefaultOptions</span> <span class='assign token'>=</span> <span class='lbrace token'>{</span><span class='symbol val'>:message</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;is not a valid color&quot;</span><span class='rbrace token'>}</span>
114
+ <span class='ValidColours constant id'>ValidColours</span> <span class='assign token'>=</span> <span class='dstring node'>%w[red green blue]</span>
115
+
116
+ <span class='def def kw'>def</span> <span class='validate identifier id'>validate</span>
117
+ <span class='super super kw'>super</span>
118
+ <span class='if if kw'>if</span> <span class='ValidColours constant id'>ValidColours</span><span class='dot token'>.</span><span class='include? fid id'>include?</span><span class='lparen token'>(</span><span class='attribute_value identifier id'>attribute_value</span><span class='rparen token'>)</span>
119
+ <span class='pass identifier id'>pass</span>
120
+ <span class='else else kw'>else</span>
121
+ <span class='fail identifier id'>fail</span>
122
+ <span class='end end kw'>end</span>
123
+ <span class='end end kw'>end</span>
124
+
125
+ <span class='end end kw'>end</span> <span class='comment val'># ValidatesPrimaryColour</span>
126
+
127
+ <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidationBuilder constant id'>ValidationBuilder</span><span class='dot token'>.</span><span class='register_macro identifier id'>register_macro</span> <span class='symbol val'>:validates_primary_colour_of</span><span class='comma token'>,</span> <span class='ValidatesPrimaryColour constant id'>ValidatesPrimaryColour</span>
128
+ </pre>
129
+
130
+ <h2 id='activerecord_integration'>ActiveRecord Integration</h2>
131
+
132
+ <p>WhyValidationsSuckIn96 features ActiveRecord support. The caveat is that it violently tears out the existing validation API so anything that uses that will break. The good news is that what it replaces the existing validation code with works as expected with features such as callbacks and preventing saves to the database when objects are invalid. All the standard ActiveRecord validation macros are available, and most have the same API to use when setting them up.</p>
133
+
134
+ <p>To use the ActiveRecord support:</p>
135
+
136
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96/rails/active_record'</span>
137
+ </pre>
138
+
139
+ <p>Then you can define validations as expected in your model classes:</p>
140
+
141
+ <pre class="code"><span class='class class kw'>class</span> <span class='Song constant id'>Song</span> <span class='lt op'>&lt;</span> <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span>
142
+ <span class='setup_validations identifier id'>setup_validations</span> <span class='do do kw'>do</span>
143
+ <span class='validates_uniqueness_of identifier id'>validates_uniqueness_of</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:scope</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='symbol val'>:artist</span>
144
+ <span class='end end kw'>end</span>
145
+ <span class='end end kw'>end</span>
146
+ </pre>
147
+
148
+ <h2 id='contributing'>Contributing</h2>
149
+
150
+ <ul>
151
+ <li>Fork the project.</li>
152
+
153
+ <li>Make your feature addition or bug fix.</li>
154
+
155
+ <li>Add tests for it. This is important so I don&#8217;t break it in a future version unintentionally.</li>
156
+
157
+ <li>Commit, do not mess with Rakefile or VERSION. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)</li>
158
+
159
+ <li>Send me a pull request.</li>
160
+ </ul>
161
+
162
+ <h2 id='copying'>Copying</h2>
163
+
164
+ <p>Copyright (c) 2009 gabrielg/thumblemonks. See LICENSE for details.</p></div></div>
165
+
166
+ <div id="footer">
167
+ Generated on Sun Dec 20 19:49:45 2009 by
168
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
169
+ 0.5.2 (ruby-1.8.7).
170
+ </div>
171
+
172
+ </body>
173
+ </html>
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html>
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=UTF-8" />
6
+ <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
7
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
8
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
9
+ <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
10
+ <base target="_parent" />
11
+ </head>
12
+ <body>
13
+ <h1 id="full_list_header">File List</h1>
14
+ <div id="search">Search: <input type="text" /></div>
15
+ <div class="clear"></div>
16
+ <ul id="full_list">
17
+
18
+
19
+ <li class="r1 ">
20
+
21
+ <a href="index.html" title="README">README</a>
22
+
23
+
24
+ </li>
25
+
26
+ </ul>
27
+ </body>
28
+ </html>
29
+
data/doc/index.html ADDED
@@ -0,0 +1,173 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>Documentation by YARD 0.5.2</title>
7
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <div id="header">
20
+ <div id="menu">
21
+
22
+ <a href="_index.html" title="Index">Index</a> &raquo;
23
+ <span class="title">File: README</span>
24
+
25
+ </div>
26
+
27
+ <div id="search">
28
+ <a id="class_list_link" href="#">Namespace List</a>
29
+ <a id="method_list_link" href="#">Method List</a>
30
+ <a id ="file_list_link" href="#">File List</a>
31
+ </div>
32
+
33
+ <div class="clear"></div>
34
+ </div>
35
+
36
+ <iframe id="search_frame"></iframe>
37
+
38
+ <div id="content"><div id='filecontents'><h1 id='whyvalidationssuckin96'>WhyValidationsSuckIn96</h1>
39
+
40
+ <h2 id='description'>Description</h2>
41
+
42
+ <p>WhyValidationsSuckIn96 is a library for adding validation support to objects. It aims to have a very minimal &#8216;surface area&#8217;, API-wise, and to be as easily testable as possible. It has no external dependencies unless you wish to use the ActiveRecord integration, in which case you clearly need ActiveRecord installed.</p>
43
+
44
+ <h2 id='documentation'>Documentation</h2>
45
+
46
+ <p>See &#8216;doc/index.html&#8217; for details, or <a href='http://thumblemonks.github.com/whyvalidationssuckin96'>check the GitHub Pages site for the project</a>.</p>
47
+
48
+ <h2 id='install'>Install</h2>
49
+
50
+ <p>gem install &#8216;whyvalidationssuckin96&#8217;</p>
51
+
52
+ <h2 id='basic_usage'>Basic Usage</h2>
53
+
54
+ <p>Require &#8216;whyvalidationssuckin96&#8217; and include the WhyValidationsSuckIn96::ValidationSupport module into your class:</p>
55
+
56
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96'</span>
57
+
58
+ <span class='class class kw'>class</span> <span class='Song constant id'>Song</span>
59
+ <span class='attr_accessor identifier id'>attr_accessor</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:artist</span>
60
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidationSupport constant id'>ValidationSupport</span>
61
+ <span class='end end kw'>end</span>
62
+ </pre>
63
+
64
+ <p>Define your validations or call pre-existing validation macros inside a validation setup block:</p>
65
+
66
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96'</span>
67
+
68
+ <span class='class class kw'>class</span> <span class='Song constant id'>Song</span>
69
+ <span class='attr_accessor identifier id'>attr_accessor</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:artist</span><span class='comma token'>,</span> <span class='symbol val'>:year</span>
70
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidationSupport constant id'>ValidationSupport</span>
71
+
72
+ <span class='setup_validations identifier id'>setup_validations</span> <span class='do do kw'>do</span>
73
+ <span class='validate identifier id'>validate</span> <span class='symbol val'>:no_eighties_crap</span> <span class='do do kw'>do</span>
74
+ <span class='if if kw'>if</span> <span class='dstring node'>%w[BonJovi Dokken]</span><span class='dot token'>.</span><span class='include? fid id'>include?</span><span class='lparen token'>(</span><span class='validatable identifier id'>validatable</span><span class='dot token'>.</span><span class='artist identifier id'>artist</span><span class='rparen token'>)</span>
75
+ <span class='fail identifier id'>fail</span>
76
+ <span class='else else kw'>else</span>
77
+ <span class='pass identifier id'>pass</span>
78
+ <span class='end end kw'>end</span>
79
+ <span class='end end kw'>end</span>
80
+
81
+ <span class='validates_presence_of identifier id'>validates_presence_of</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:artist</span>
82
+ <span class='validates_numericality_of identifier id'>validates_numericality_of</span> <span class='symbol val'>:year</span>
83
+ <span class='end end kw'>end</span>
84
+ <span class='end end kw'>end</span>
85
+ </pre>
86
+
87
+ <p>Check instances of your class for validity and inspect the failed validations:</p>
88
+
89
+ <pre class="code"><span class='song identifier id'>song</span> <span class='assign token'>=</span> <span class='Song constant id'>Song</span><span class='dot token'>.</span><span class='new identifier id'>new</span>
90
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='valid? fid id'>valid?</span>
91
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='invalid? fid id'>invalid?</span>
92
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='failed_validations identifier id'>failed_validations</span>
93
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='passed_validations identifier id'>passed_validations</span>
94
+ <span class='song identifier id'>song</span><span class='dot token'>.</span><span class='all_validations identifier id'>all_validations</span>
95
+ </pre>
96
+
97
+ <p>Easily inspect and test for the presence of validations on your class:</p>
98
+
99
+ <pre class="code"><span class='Song constant id'>Song</span><span class='dot token'>.</span><span class='validation_collection identifier id'>validation_collection</span><span class='dot token'>.</span><span class='detect identifier id'>detect</span> <span class='do do kw'>do</span> <span class='bitor op'>|</span><span class='lparen token'>(</span><span class='klass identifier id'>klass</span><span class='comma token'>,</span> <span class='opts identifier id'>opts</span><span class='rparen token'>)</span><span class='bitor op'>|</span>
100
+ <span class='klass identifier id'>klass</span><span class='dot token'>.</span><span class='is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidatesPresence constant id'>ValidatesPresence</span><span class='rparen token'>)</span>
101
+ <span class='end end kw'>end</span>
102
+ </pre>
103
+
104
+ <p>Create your own reusable and testable validations:</p>
105
+
106
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96/skippable_validation'</span>
107
+ <span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96/attribute_based_validation'</span>
108
+
109
+ <span class='class class kw'>class</span> <span class='ValidatesPrimaryColour constant id'>ValidatesPrimaryColour</span> <span class='lt op'>&lt;</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='Validation constant id'>Validation</span>
110
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='SkippableValidation constant id'>SkippableValidation</span>
111
+ <span class='include identifier id'>include</span> <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='AttributeBasedValidation constant id'>AttributeBasedValidation</span>
112
+
113
+ <span class='DefaultOptions constant id'>DefaultOptions</span> <span class='assign token'>=</span> <span class='lbrace token'>{</span><span class='symbol val'>:message</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;is not a valid color&quot;</span><span class='rbrace token'>}</span>
114
+ <span class='ValidColours constant id'>ValidColours</span> <span class='assign token'>=</span> <span class='dstring node'>%w[red green blue]</span>
115
+
116
+ <span class='def def kw'>def</span> <span class='validate identifier id'>validate</span>
117
+ <span class='super super kw'>super</span>
118
+ <span class='if if kw'>if</span> <span class='ValidColours constant id'>ValidColours</span><span class='dot token'>.</span><span class='include? fid id'>include?</span><span class='lparen token'>(</span><span class='attribute_value identifier id'>attribute_value</span><span class='rparen token'>)</span>
119
+ <span class='pass identifier id'>pass</span>
120
+ <span class='else else kw'>else</span>
121
+ <span class='fail identifier id'>fail</span>
122
+ <span class='end end kw'>end</span>
123
+ <span class='end end kw'>end</span>
124
+
125
+ <span class='end end kw'>end</span> <span class='comment val'># ValidatesPrimaryColour</span>
126
+
127
+ <span class='WhyValidationsSuckIn96 constant id'>WhyValidationsSuckIn96</span><span class='colon2 op'>::</span><span class='ValidationBuilder constant id'>ValidationBuilder</span><span class='dot token'>.</span><span class='register_macro identifier id'>register_macro</span> <span class='symbol val'>:validates_primary_colour_of</span><span class='comma token'>,</span> <span class='ValidatesPrimaryColour constant id'>ValidatesPrimaryColour</span>
128
+ </pre>
129
+
130
+ <h2 id='activerecord_integration'>ActiveRecord Integration</h2>
131
+
132
+ <p>WhyValidationsSuckIn96 features ActiveRecord support. The caveat is that it violently tears out the existing validation API so anything that uses that will break. The good news is that what it replaces the existing validation code with works as expected with features such as callbacks and preventing saves to the database when objects are invalid. All the standard ActiveRecord validation macros are available, and most have the same API to use when setting them up.</p>
133
+
134
+ <p>To use the ActiveRecord support:</p>
135
+
136
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'whyvalidationssuckin96/rails/active_record'</span>
137
+ </pre>
138
+
139
+ <p>Then you can define validations as expected in your model classes:</p>
140
+
141
+ <pre class="code"><span class='class class kw'>class</span> <span class='Song constant id'>Song</span> <span class='lt op'>&lt;</span> <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span>
142
+ <span class='setup_validations identifier id'>setup_validations</span> <span class='do do kw'>do</span>
143
+ <span class='validates_uniqueness_of identifier id'>validates_uniqueness_of</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:scope</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='symbol val'>:artist</span>
144
+ <span class='end end kw'>end</span>
145
+ <span class='end end kw'>end</span>
146
+ </pre>
147
+
148
+ <h2 id='contributing'>Contributing</h2>
149
+
150
+ <ul>
151
+ <li>Fork the project.</li>
152
+
153
+ <li>Make your feature addition or bug fix.</li>
154
+
155
+ <li>Add tests for it. This is important so I don&#8217;t break it in a future version unintentionally.</li>
156
+
157
+ <li>Commit, do not mess with Rakefile or VERSION. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)</li>
158
+
159
+ <li>Send me a pull request.</li>
160
+ </ul>
161
+
162
+ <h2 id='copying'>Copying</h2>
163
+
164
+ <p>Copyright (c) 2009 gabrielg/thumblemonks. See LICENSE for details.</p></div></div>
165
+
166
+ <div id="footer">
167
+ Generated on Sun Dec 20 19:49:45 2009 by
168
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
169
+ 0.5.2 (ruby-1.8.7).
170
+ </div>
171
+
172
+ </body>
173
+ </html>
data/doc/js/app.js ADDED
@@ -0,0 +1,91 @@
1
+ function createSourceLinks() {
2
+ $('.method_details_list .source_code').
3
+ before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
4
+ $('.toggleSource').toggle(function() {
5
+ $(this).parent().next().slideDown(100);
6
+ $(this).text("Hide source");
7
+ },
8
+ function() {
9
+ $(this).parent().next().slideUp(100);
10
+ $(this).text("View source");
11
+ });
12
+ }
13
+
14
+ function createDefineLinks() {
15
+ var tHeight = 0;
16
+ $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
17
+ $('.toggleDefines').toggle(function() {
18
+ tHeight = $(this).parent().prev().height();
19
+ $(this).prev().show();
20
+ $(this).parent().prev().height($(this).parent().height());
21
+ $(this).text("(less)");
22
+ },
23
+ function() {
24
+ $(this).prev().hide();
25
+ $(this).parent().prev().height(tHeight);
26
+ $(this).text("more...")
27
+ });
28
+ }
29
+
30
+ function createFullTreeLinks() {
31
+ var tHeight = 0;
32
+ $('.inheritanceTree').toggle(function() {
33
+ tHeight = $(this).parent().prev().height();
34
+ $(this).prev().prev().hide();
35
+ $(this).prev().show();
36
+ $(this).text("(hide)");
37
+ $(this).parent().prev().height($(this).parent().height());
38
+ },
39
+ function() {
40
+ $(this).prev().prev().show();
41
+ $(this).prev().hide();
42
+ $(this).parent().prev().height(tHeight);
43
+ $(this).text("show all")
44
+ });
45
+ }
46
+
47
+ function fixBoxInfoHeights() {
48
+ $('dl.box dd.r1, dl.box dd.r2').each(function() {
49
+ $(this).prev().height($(this).height());
50
+ });
51
+ }
52
+
53
+ function searchFrameLinks() {
54
+ $('#method_list_link').click(function() {
55
+ toggleSearchFrame(this, relpath + 'method_list.html');
56
+ });
57
+
58
+ $('#class_list_link').click(function() {
59
+ toggleSearchFrame(this, relpath + 'class_list.html');
60
+ });
61
+
62
+ $('#file_list_link').click(function() {
63
+ toggleSearchFrame(this, relpath + 'file_list.html');
64
+ });
65
+ }
66
+
67
+ function toggleSearchFrame(id, link) {
68
+ var frame = $('#search_frame');
69
+ $('#search a').removeClass('active').addClass('inactive');
70
+ if (frame.attr('src') == link && frame.css('display') != "none") {
71
+ frame.slideUp(100);
72
+ $('#search a').removeClass('active inactive');
73
+ }
74
+ else {
75
+ $(id).addClass('active').removeClass('inactive');
76
+ frame.attr('src', link).slideDown(100);
77
+ }
78
+ }
79
+
80
+ function linkSummaries() {
81
+ $('.summary_signature').click(function() {
82
+ window.parent.location = $(this).find('a').attr('href');
83
+ });
84
+ }
85
+
86
+ $(createSourceLinks);
87
+ $(createDefineLinks);
88
+ $(createFullTreeLinks);
89
+ $(fixBoxInfoHeights);
90
+ $(searchFrameLinks);
91
+ $(linkSummaries);
@@ -0,0 +1,39 @@
1
+ function fullListSearch() {
2
+ $('#search input').keyup(function() {
3
+ var value = this.value.toLowerCase();
4
+ if (value == "") {
5
+ $('#full_list li').show();
6
+ }
7
+ else {
8
+ $('#full_list li').each(function() {
9
+ if ($(this).children('a').text().toLowerCase().indexOf(value) == -1) {
10
+ $(this).hide();
11
+ }
12
+ else {
13
+ $(this).show();
14
+ }
15
+ });
16
+ }
17
+ $('#full_list li:even:visible').removeClass('r2').addClass('r1');
18
+ $('#full_list li:odd:visible').removeClass('r1').addClass('r2');
19
+
20
+ if ($('#full_list li:visible').size() == 0) {
21
+ $('#noresults').fadeIn();
22
+ }
23
+ else {
24
+ $('#noresults').hide();
25
+ }
26
+ });
27
+
28
+ $('#search input').focus();
29
+ $('#full_list').after("<div id='noresults'>No results were found.</div>")
30
+ }
31
+
32
+ function linkList() {
33
+ $('#full_list li').click(function() {
34
+ window.parent.location = $(this).find('a').attr('href');
35
+ });
36
+ }
37
+
38
+ $(fullListSearch);
39
+ $(linkList);