mack-active_record 0.8.1 → 0.8.2

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 (379) hide show
  1. data/lib/gems/activerecord-2.2.2/lib/active_record/aggregations.rb +261 -0
  2. data/lib/gems/activerecord-2.2.2/lib/active_record/association_preload.rb +374 -0
  3. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb +453 -0
  4. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/association_proxy.rb +272 -0
  5. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/belongs_to_association.rb +58 -0
  6. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/belongs_to_polymorphic_association.rb +49 -0
  7. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/has_and_belongs_to_many_association.rb +121 -0
  8. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/has_many_association.rb +121 -0
  9. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/has_many_through_association.rb +256 -0
  10. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/has_one_association.rb +115 -0
  11. data/lib/gems/activerecord-2.2.2/lib/active_record/associations/has_one_through_association.rb +31 -0
  12. data/lib/gems/activerecord-2.2.2/lib/active_record/associations.rb +2227 -0
  13. data/lib/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb +387 -0
  14. data/lib/gems/activerecord-2.2.2/lib/active_record/base.rb +2967 -0
  15. data/lib/gems/activerecord-2.2.2/lib/active_record/calculations.rb +299 -0
  16. data/lib/gems/activerecord-2.2.2/lib/active_record/callbacks.rb +331 -0
  17. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb +355 -0
  18. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb +136 -0
  19. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb +201 -0
  20. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb +94 -0
  21. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/quoting.rb +69 -0
  22. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb +705 -0
  23. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_statements.rb +434 -0
  24. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb +210 -0
  25. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb +585 -0
  26. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb +1065 -0
  27. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
  28. data/lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/sqlite_adapter.rb +418 -0
  29. data/lib/gems/activerecord-2.2.2/lib/active_record/dirty.rb +183 -0
  30. data/lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb +41 -0
  31. data/lib/gems/activerecord-2.2.2/lib/active_record/fixtures.rb +998 -0
  32. data/lib/gems/activerecord-2.2.2/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
  33. data/lib/gems/activerecord-2.2.2/lib/active_record/locale/en.yml +54 -0
  34. data/lib/gems/activerecord-2.2.2/lib/active_record/locking/optimistic.rb +148 -0
  35. data/lib/gems/activerecord-2.2.2/lib/active_record/locking/pessimistic.rb +77 -0
  36. data/lib/gems/activerecord-2.2.2/lib/active_record/migration.rb +560 -0
  37. data/lib/gems/activerecord-2.2.2/lib/active_record/named_scope.rb +181 -0
  38. data/lib/gems/activerecord-2.2.2/lib/active_record/observer.rb +197 -0
  39. data/lib/gems/activerecord-2.2.2/lib/active_record/query_cache.rb +21 -0
  40. data/lib/gems/activerecord-2.2.2/lib/active_record/reflection.rb +307 -0
  41. data/lib/gems/activerecord-2.2.2/lib/active_record/schema.rb +51 -0
  42. data/lib/gems/activerecord-2.2.2/lib/active_record/schema_dumper.rb +177 -0
  43. data/lib/gems/activerecord-2.2.2/lib/active_record/serialization.rb +98 -0
  44. data/lib/gems/activerecord-2.2.2/lib/active_record/serializers/json_serializer.rb +80 -0
  45. data/lib/gems/activerecord-2.2.2/lib/active_record/serializers/xml_serializer.rb +338 -0
  46. data/lib/gems/activerecord-2.2.2/lib/active_record/test_case.rb +60 -0
  47. data/lib/gems/activerecord-2.2.2/lib/active_record/timestamp.rb +41 -0
  48. data/lib/gems/activerecord-2.2.2/lib/active_record/transactions.rb +185 -0
  49. data/lib/gems/activerecord-2.2.2/lib/active_record/validations.rb +1061 -0
  50. data/lib/gems/activerecord-2.2.2/lib/active_record/version.rb +9 -0
  51. data/lib/gems/activerecord-2.2.2/lib/active_record.rb +81 -0
  52. data/lib/gems/activerecord-2.2.2/lib/activerecord.rb +1 -0
  53. data/lib/gems/activesupport-2.2.2/lib/active_support/base64.rb +33 -0
  54. data/lib/gems/activesupport-2.2.2/lib/active_support/basic_object.rb +24 -0
  55. data/lib/gems/activesupport-2.2.2/lib/active_support/buffered_logger.rb +122 -0
  56. data/lib/gems/activesupport-2.2.2/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
  57. data/lib/gems/activesupport-2.2.2/lib/active_support/cache/drb_store.rb +15 -0
  58. data/lib/gems/activesupport-2.2.2/lib/active_support/cache/file_store.rb +72 -0
  59. data/lib/gems/activesupport-2.2.2/lib/active_support/cache/mem_cache_store.rb +127 -0
  60. data/lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb +52 -0
  61. data/lib/gems/activesupport-2.2.2/lib/active_support/cache/synchronized_memory_store.rb +47 -0
  62. data/lib/gems/activesupport-2.2.2/lib/active_support/cache.rb +223 -0
  63. data/lib/gems/activesupport-2.2.2/lib/active_support/callbacks.rb +280 -0
  64. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/array/access.rb +53 -0
  65. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/array/conversions.rb +183 -0
  66. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/array/extract_options.rb +20 -0
  67. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/array/grouping.rb +106 -0
  68. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/array/random_access.rb +12 -0
  69. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/array.rb +13 -0
  70. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/base64/encoding.rb +16 -0
  71. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/base64.rb +4 -0
  72. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/benchmark.rb +12 -0
  73. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/bigdecimal/conversions.rb +37 -0
  74. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/bigdecimal.rb +6 -0
  75. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/blank.rb +58 -0
  76. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
  77. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/cgi.rb +5 -0
  78. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/class/attribute_accessors.rb +54 -0
  79. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/class/delegating_attributes.rb +46 -0
  80. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
  81. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/class/removal.rb +50 -0
  82. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/class.rb +4 -0
  83. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/date/behavior.rb +42 -0
  84. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/date/calculations.rb +230 -0
  85. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/date/conversions.rb +107 -0
  86. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/date.rb +10 -0
  87. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/date_time/calculations.rb +126 -0
  88. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/date_time/conversions.rb +96 -0
  89. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/date_time.rb +12 -0
  90. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/duplicable.rb +43 -0
  91. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/enumerable.rb +107 -0
  92. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/exception.rb +41 -0
  93. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/file/atomic.rb +46 -0
  94. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/file.rb +5 -0
  95. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/float/rounding.rb +24 -0
  96. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/float/time.rb +27 -0
  97. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/float.rb +7 -0
  98. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/conversions.rb +259 -0
  99. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
  100. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/diff.rb +19 -0
  101. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/except.rb +25 -0
  102. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
  103. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/keys.rb +52 -0
  104. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
  105. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash/slice.rb +33 -0
  106. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/hash.rb +14 -0
  107. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/integer/even_odd.rb +29 -0
  108. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/integer/inflections.rb +20 -0
  109. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/integer/time.rb +45 -0
  110. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/integer.rb +9 -0
  111. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
  112. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel/daemonizing.rb +7 -0
  113. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel/debugger.rb +13 -0
  114. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel/reporting.rb +59 -0
  115. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel/requires.rb +24 -0
  116. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel.rb +5 -0
  117. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/load_error.rb +38 -0
  118. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb +143 -0
  119. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/aliasing.rb +74 -0
  120. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
  121. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/attr_internal.rb +32 -0
  122. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/attribute_accessors.rb +58 -0
  123. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/delegation.rb +95 -0
  124. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/inclusion.rb +30 -0
  125. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/introspection.rb +90 -0
  126. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/loading.rb +23 -0
  127. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/model_naming.rb +23 -0
  128. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module/synchronization.rb +39 -0
  129. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/module.rb +23 -0
  130. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/name_error.rb +17 -0
  131. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/numeric/bytes.rb +44 -0
  132. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/numeric/conversions.rb +19 -0
  133. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/numeric/time.rb +81 -0
  134. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/numeric.rb +9 -0
  135. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/object/conversions.rb +14 -0
  136. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/object/extending.rb +80 -0
  137. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/object/instance_variables.rb +74 -0
  138. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/object/metaclass.rb +13 -0
  139. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/object/misc.rb +74 -0
  140. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/object.rb +5 -0
  141. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
  142. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/pathname.rb +7 -0
  143. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/proc.rb +12 -0
  144. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/process/daemon.rb +25 -0
  145. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/process.rb +1 -0
  146. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range/blockless_step.rb +32 -0
  147. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range/conversions.rb +27 -0
  148. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range/include_range.rb +30 -0
  149. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range/overlaps.rb +15 -0
  150. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range.rb +11 -0
  151. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/rexml.rb +36 -0
  152. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/access.rb +82 -0
  153. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/behavior.rb +13 -0
  154. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/conversions.rb +28 -0
  155. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/filters.rb +26 -0
  156. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/inflections.rb +167 -0
  157. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/iterators.rb +21 -0
  158. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/multibyte.rb +81 -0
  159. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/starts_ends_with.rb +35 -0
  160. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string/xchar.rb +11 -0
  161. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/string.rb +22 -0
  162. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/symbol.rb +14 -0
  163. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time/behavior.rb +13 -0
  164. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time/calculations.rb +303 -0
  165. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time/conversions.rb +90 -0
  166. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time/zones.rb +86 -0
  167. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time.rb +42 -0
  168. data/lib/gems/activesupport-2.2.2/lib/active_support/core_ext.rb +4 -0
  169. data/lib/gems/activesupport-2.2.2/lib/active_support/dependencies.rb +621 -0
  170. data/lib/gems/activesupport-2.2.2/lib/active_support/deprecation.rb +243 -0
  171. data/lib/gems/activesupport-2.2.2/lib/active_support/duration.rb +96 -0
  172. data/lib/gems/activesupport-2.2.2/lib/active_support/gzip.rb +25 -0
  173. data/lib/gems/activesupport-2.2.2/lib/active_support/inflections.rb +55 -0
  174. data/lib/gems/activesupport-2.2.2/lib/active_support/inflector.rb +397 -0
  175. data/lib/gems/activesupport-2.2.2/lib/active_support/json/decoding.rb +63 -0
  176. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/date.rb +21 -0
  177. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/date_time.rb +21 -0
  178. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/enumerable.rb +12 -0
  179. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/false_class.rb +5 -0
  180. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/hash.rb +47 -0
  181. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/nil_class.rb +5 -0
  182. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/numeric.rb +5 -0
  183. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/object.rb +6 -0
  184. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/regexp.rb +5 -0
  185. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/string.rb +36 -0
  186. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/symbol.rb +5 -0
  187. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/time.rb +21 -0
  188. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/true_class.rb +5 -0
  189. data/lib/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb +37 -0
  190. data/lib/gems/activesupport-2.2.2/lib/active_support/json/variable.rb +10 -0
  191. data/lib/gems/activesupport-2.2.2/lib/active_support/json.rb +23 -0
  192. data/lib/gems/activesupport-2.2.2/lib/active_support/locale/en.yml +32 -0
  193. data/lib/gems/activesupport-2.2.2/lib/active_support/memoizable.rb +82 -0
  194. data/lib/gems/activesupport-2.2.2/lib/active_support/multibyte/chars.rb +679 -0
  195. data/lib/gems/activesupport-2.2.2/lib/active_support/multibyte/exceptions.rb +8 -0
  196. data/lib/gems/activesupport-2.2.2/lib/active_support/multibyte/unicode_database.rb +71 -0
  197. data/lib/gems/activesupport-2.2.2/lib/active_support/multibyte.rb +33 -0
  198. data/lib/gems/activesupport-2.2.2/lib/active_support/option_merger.rb +17 -0
  199. data/lib/gems/activesupport-2.2.2/lib/active_support/ordered_hash.rb +58 -0
  200. data/lib/gems/activesupport-2.2.2/lib/active_support/ordered_options.rb +19 -0
  201. data/lib/gems/activesupport-2.2.2/lib/active_support/rescuable.rb +108 -0
  202. data/lib/gems/activesupport-2.2.2/lib/active_support/secure_random.rb +197 -0
  203. data/lib/gems/activesupport-2.2.2/lib/active_support/string_inquirer.rb +21 -0
  204. data/lib/gems/activesupport-2.2.2/lib/active_support/test_case.rb +24 -0
  205. data/lib/gems/activesupport-2.2.2/lib/active_support/testing/core_ext/test/unit/assertions.rb +72 -0
  206. data/lib/gems/activesupport-2.2.2/lib/active_support/testing/core_ext/test.rb +6 -0
  207. data/lib/gems/activesupport-2.2.2/lib/active_support/testing/default.rb +9 -0
  208. data/lib/gems/activesupport-2.2.2/lib/active_support/testing/performance.rb +452 -0
  209. data/lib/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb +120 -0
  210. data/lib/gems/activesupport-2.2.2/lib/active_support/time_with_zone.rb +328 -0
  211. data/lib/gems/activesupport-2.2.2/lib/active_support/values/time_zone.rb +403 -0
  212. data/lib/gems/activesupport-2.2.2/lib/active_support/values/unicode_tables.dat +0 -0
  213. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
  214. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
  215. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
  216. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
  217. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
  218. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
  219. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
  220. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
  221. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +216 -0
  222. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb +53 -0
  223. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/i18n-0.0.1/i18n.rb +194 -0
  224. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb +849 -0
  225. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +47 -0
  226. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +228 -0
  227. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +55 -0
  228. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +219 -0
  229. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +40 -0
  230. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +18 -0
  231. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
  232. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +22 -0
  233. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +23 -0
  234. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
  235. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +86 -0
  236. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +23 -0
  237. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +23 -0
  238. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +283 -0
  239. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +136 -0
  240. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +204 -0
  241. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +161 -0
  242. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +27 -0
  243. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +274 -0
  244. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
  245. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +194 -0
  246. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +22 -0
  247. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +35 -0
  248. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +232 -0
  249. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +139 -0
  250. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +144 -0
  251. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +131 -0
  252. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +282 -0
  253. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +30 -0
  254. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +74 -0
  255. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +205 -0
  256. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +171 -0
  257. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +288 -0
  258. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +196 -0
  259. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +67 -0
  260. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +73 -0
  261. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +161 -0
  262. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +20 -0
  263. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +33 -0
  264. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +30 -0
  265. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +27 -0
  266. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
  267. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
  268. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +30 -0
  269. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
  270. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +20 -0
  271. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
  272. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +30 -0
  273. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +20 -0
  274. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +25 -0
  275. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
  276. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
  277. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +18 -0
  278. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +163 -0
  279. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +18 -0
  280. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
  281. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +24 -0
  282. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +18 -0
  283. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +34 -0
  284. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +35 -0
  285. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +33 -0
  286. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +59 -0
  287. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +47 -0
  288. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
  289. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +121 -0
  290. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +30 -0
  291. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
  292. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +33 -0
  293. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
  294. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
  295. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
  296. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +165 -0
  297. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +270 -0
  298. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
  299. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
  300. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +187 -0
  301. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +35 -0
  302. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +29 -0
  303. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +193 -0
  304. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +185 -0
  305. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +37 -0
  306. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +185 -0
  307. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +16 -0
  308. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
  309. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +185 -0
  310. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +163 -0
  311. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +188 -0
  312. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +13 -0
  313. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +232 -0
  314. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +181 -0
  315. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +197 -0
  316. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
  317. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +276 -0
  318. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +163 -0
  319. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +218 -0
  320. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +168 -0
  321. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +268 -0
  322. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
  323. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +288 -0
  324. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +211 -0
  325. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +170 -0
  326. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +181 -0
  327. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +232 -0
  328. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +187 -0
  329. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +176 -0
  330. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +215 -0
  331. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
  332. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +13 -0
  333. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +173 -0
  334. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +165 -0
  335. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +172 -0
  336. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +183 -0
  337. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +170 -0
  338. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +212 -0
  339. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +13 -0
  340. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +202 -0
  341. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +23 -0
  342. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +22 -0
  343. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
  344. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +20 -0
  345. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +25 -0
  346. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +25 -0
  347. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
  348. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
  349. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
  350. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +52 -0
  351. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +51 -0
  352. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +44 -0
  353. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +98 -0
  354. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +56 -0
  355. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +292 -0
  356. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +508 -0
  357. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +56 -0
  358. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +40 -0
  359. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +94 -0
  360. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +198 -0
  361. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +129 -0
  362. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +33 -0
  363. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
  364. data/lib/gems/activesupport-2.2.2/lib/active_support/vendor.rb +34 -0
  365. data/lib/gems/activesupport-2.2.2/lib/active_support/version.rb +9 -0
  366. data/lib/gems/activesupport-2.2.2/lib/active_support/whiny_nil.rb +58 -0
  367. data/lib/gems/activesupport-2.2.2/lib/active_support.rb +61 -0
  368. data/lib/gems/activesupport-2.2.2/lib/activesupport.rb +1 -0
  369. data/lib/gems.rb +13 -0
  370. data/lib/mack-active_record/database.rb +4 -4
  371. data/lib/mack-active_record/migration_generator/migration_generator.rb +6 -2
  372. data/lib/mack-active_record/model_generator/manifest.yml +3 -3
  373. data/lib/mack-active_record/model_generator/model_generator.rb +8 -1
  374. data/lib/mack-active_record/model_generator/templates/model.rb.template +1 -1
  375. data/lib/mack-active_record/model_generator/templates/rspec.rb.template +1 -1
  376. data/lib/mack-active_record/model_generator/templates/test.rb.template +1 -1
  377. data/lib/mack-active_record.rb +3 -1
  378. data/lib/mack-active_record_tasks.rb +3 -0
  379. metadata +457 -16
@@ -0,0 +1,1061 @@
1
+ module ActiveRecord
2
+ # Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the
3
+ # +record+ method to retrieve the record which did not validate.
4
+ # begin
5
+ # complex_operation_that_calls_save!_internally
6
+ # rescue ActiveRecord::RecordInvalid => invalid
7
+ # puts invalid.record.errors
8
+ # end
9
+ class RecordInvalid < ActiveRecordError
10
+ attr_reader :record
11
+ def initialize(record)
12
+ @record = record
13
+ super("Validation failed: #{@record.errors.full_messages.join(", ")}")
14
+ end
15
+ end
16
+
17
+ # Active Record validation is reported to and from this object, which is used by Base#save to
18
+ # determine whether the object is in a valid state to be saved. See usage example in Validations.
19
+ class Errors
20
+ include Enumerable
21
+
22
+ class << self
23
+ def default_error_messages
24
+ ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages has been deprecated. Please use I18n.translate('activerecord.errors.messages').")
25
+ I18n.translate 'activerecord.errors.messages'
26
+ end
27
+ end
28
+
29
+ def initialize(base) # :nodoc:
30
+ @base, @errors = base, {}
31
+ end
32
+
33
+ # Adds an error to the base object instead of any particular attribute. This is used
34
+ # to report errors that don't tie to any specific attribute, but rather to the object
35
+ # as a whole. These error messages don't get prepended with any field name when iterating
36
+ # with +each_full+, so they should be complete sentences.
37
+ def add_to_base(msg)
38
+ add(:base, msg)
39
+ end
40
+
41
+ # Adds an error message (+messsage+) to the +attribute+, which will be returned on a call to <tt>on(attribute)</tt>
42
+ # for the same attribute and ensure that this error object returns false when asked if <tt>empty?</tt>. More than one
43
+ # error can be added to the same +attribute+ in which case an array will be returned on a call to <tt>on(attribute)</tt>.
44
+ # If no +messsage+ is supplied, :invalid is assumed.
45
+ # If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error).
46
+ def add(attribute, message = nil, options = {})
47
+ message ||= :invalid
48
+ message = generate_message(attribute, message, options) if message.is_a?(Symbol)
49
+ @errors[attribute.to_s] ||= []
50
+ @errors[attribute.to_s] << message
51
+ end
52
+
53
+ # Will add an error message to each of the attributes in +attributes+ that is empty.
54
+ def add_on_empty(attributes, custom_message = nil)
55
+ for attr in [attributes].flatten
56
+ value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
57
+ is_empty = value.respond_to?(:empty?) ? value.empty? : false
58
+ add(attr, :empty, :default => custom_message) unless !value.nil? && !is_empty
59
+ end
60
+ end
61
+
62
+ # Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?).
63
+ def add_on_blank(attributes, custom_message = nil)
64
+ for attr in [attributes].flatten
65
+ value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
66
+ add(attr, :blank, :default => custom_message) if value.blank?
67
+ end
68
+ end
69
+
70
+ # Translates an error message in it's default scope (<tt>activerecord.errrors.messages</tt>).
71
+ # Error messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it's not there,
72
+ # it's looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the
73
+ # default message (e.g. <tt>activerecord.errors.messages.MESSAGE</tt>). The translated model name,
74
+ # translated attribute name and the value are available for interpolation.
75
+ #
76
+ # When using inheritence in your models, it will check all the inherited models too, but only if the model itself
77
+ # hasn't been found. Say you have <tt>class Admin < User; end</tt> and you wanted the translation for the <tt>:blank</tt>
78
+ # error +message+ for the <tt>title</tt> +attribute+, it looks for these translations:
79
+ #
80
+ # <ol>
81
+ # <li><tt>activerecord.errors.models.admin.attributes.title.blank</tt></li>
82
+ # <li><tt>activerecord.errors.models.admin.blank</tt></li>
83
+ # <li><tt>activerecord.errors.models.user.attributes.title.blank</tt></li>
84
+ # <li><tt>activerecord.errors.models.user.blank</tt></li>
85
+ # <li><tt>activerecord.errors.messages.blank</tt></li>
86
+ # <li>any default you provided through the +options+ hash (in the activerecord.errors scope)</li>
87
+ # </ol>
88
+ def generate_message(attribute, message = :invalid, options = {})
89
+
90
+ message, options[:default] = options[:default], message if options[:default].is_a?(Symbol)
91
+
92
+ defaults = @base.class.self_and_descendents_from_active_record.map do |klass|
93
+ [ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}",
94
+ :"models.#{klass.name.underscore}.#{message}" ]
95
+ end
96
+
97
+ defaults << options.delete(:default)
98
+ defaults = defaults.compact.flatten << :"messages.#{message}"
99
+
100
+ key = defaults.shift
101
+ value = @base.respond_to?(attribute) ? @base.send(attribute) : nil
102
+
103
+ options = { :default => defaults,
104
+ :model => @base.class.human_name,
105
+ :attribute => @base.class.human_attribute_name(attribute.to_s),
106
+ :value => value,
107
+ :scope => [:activerecord, :errors]
108
+ }.merge(options)
109
+
110
+ I18n.translate(key, options)
111
+ end
112
+
113
+ # Returns true if the specified +attribute+ has errors associated with it.
114
+ #
115
+ # class Company < ActiveRecord::Base
116
+ # validates_presence_of :name, :address, :email
117
+ # validates_length_of :name, :in => 5..30
118
+ # end
119
+ #
120
+ # company = Company.create(:address => '123 First St.')
121
+ # company.errors.invalid?(:name) # => true
122
+ # company.errors.invalid?(:address) # => false
123
+ def invalid?(attribute)
124
+ !@errors[attribute.to_s].nil?
125
+ end
126
+
127
+ # Returns +nil+, if no errors are associated with the specified +attribute+.
128
+ # Returns the error message, if one error is associated with the specified +attribute+.
129
+ # Returns an array of error messages, if more than one error is associated with the specified +attribute+.
130
+ #
131
+ # class Company < ActiveRecord::Base
132
+ # validates_presence_of :name, :address, :email
133
+ # validates_length_of :name, :in => 5..30
134
+ # end
135
+ #
136
+ # company = Company.create(:address => '123 First St.')
137
+ # company.errors.on(:name) # => ["is too short (minimum is 5 characters)", "can't be blank"]
138
+ # company.errors.on(:email) # => "can't be blank"
139
+ # company.errors.on(:address) # => nil
140
+ def on(attribute)
141
+ errors = @errors[attribute.to_s]
142
+ return nil if errors.nil?
143
+ errors.size == 1 ? errors.first : errors
144
+ end
145
+
146
+ alias :[] :on
147
+
148
+ # Returns errors assigned to the base object through +add_to_base+ according to the normal rules of <tt>on(attribute)</tt>.
149
+ def on_base
150
+ on(:base)
151
+ end
152
+
153
+ # Yields each attribute and associated message per error added.
154
+ #
155
+ # class Company < ActiveRecord::Base
156
+ # validates_presence_of :name, :address, :email
157
+ # validates_length_of :name, :in => 5..30
158
+ # end
159
+ #
160
+ # company = Company.create(:address => '123 First St.')
161
+ # company.errors.each{|attr,msg| puts "#{attr} - #{msg}" }
162
+ # # => name - is too short (minimum is 5 characters)
163
+ # # name - can't be blank
164
+ # # address - can't be blank
165
+ def each
166
+ @errors.each_key { |attr| @errors[attr].each { |msg| yield attr, msg } }
167
+ end
168
+
169
+ # Yields each full error message added. So <tt>Person.errors.add("first_name", "can't be empty")</tt> will be returned
170
+ # through iteration as "First name can't be empty".
171
+ #
172
+ # class Company < ActiveRecord::Base
173
+ # validates_presence_of :name, :address, :email
174
+ # validates_length_of :name, :in => 5..30
175
+ # end
176
+ #
177
+ # company = Company.create(:address => '123 First St.')
178
+ # company.errors.each_full{|msg| puts msg }
179
+ # # => Name is too short (minimum is 5 characters)
180
+ # # Name can't be blank
181
+ # # Address can't be blank
182
+ def each_full
183
+ full_messages.each { |msg| yield msg }
184
+ end
185
+
186
+ # Returns all the full error messages in an array.
187
+ #
188
+ # class Company < ActiveRecord::Base
189
+ # validates_presence_of :name, :address, :email
190
+ # validates_length_of :name, :in => 5..30
191
+ # end
192
+ #
193
+ # company = Company.create(:address => '123 First St.')
194
+ # company.errors.full_messages # =>
195
+ # ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Address can't be blank"]
196
+ def full_messages(options = {})
197
+ full_messages = []
198
+
199
+ @errors.each_key do |attr|
200
+ @errors[attr].each do |message|
201
+ next unless message
202
+
203
+ if attr == "base"
204
+ full_messages << message
205
+ else
206
+ #key = :"activerecord.att.#{@base.class.name.underscore.to_sym}.#{attr}"
207
+ attr_name = @base.class.human_attribute_name(attr)
208
+ full_messages << attr_name + ' ' + message
209
+ end
210
+ end
211
+ end
212
+ full_messages
213
+ end
214
+
215
+ # Returns true if no errors have been added.
216
+ def empty?
217
+ @errors.empty?
218
+ end
219
+
220
+ # Removes all errors that have been added.
221
+ def clear
222
+ @errors = {}
223
+ end
224
+
225
+ # Returns the total number of errors added. Two errors added to the same attribute will be counted as such.
226
+ def size
227
+ @errors.values.inject(0) { |error_count, attribute| error_count + attribute.size }
228
+ end
229
+
230
+ alias_method :count, :size
231
+ alias_method :length, :size
232
+
233
+ # Returns an XML representation of this error object.
234
+ #
235
+ # class Company < ActiveRecord::Base
236
+ # validates_presence_of :name, :address, :email
237
+ # validates_length_of :name, :in => 5..30
238
+ # end
239
+ #
240
+ # company = Company.create(:address => '123 First St.')
241
+ # company.errors.to_xml
242
+ # # => <?xml version="1.0" encoding="UTF-8"?>
243
+ # # <errors>
244
+ # # <error>Name is too short (minimum is 5 characters)</error>
245
+ # # <error>Name can't be blank</error>
246
+ # # <error>Address can't be blank</error>
247
+ # # </errors>
248
+ def to_xml(options={})
249
+ options[:root] ||= "errors"
250
+ options[:indent] ||= 2
251
+ options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
252
+
253
+ options[:builder].instruct! unless options.delete(:skip_instruct)
254
+ options[:builder].errors do |e|
255
+ full_messages.each { |msg| e.error(msg) }
256
+ end
257
+ end
258
+
259
+ end
260
+
261
+
262
+ # Please do have a look at ActiveRecord::Validations::ClassMethods for a higher level of validations.
263
+ #
264
+ # Active Records implement validation by overwriting Base#validate (or the variations, +validate_on_create+ and
265
+ # +validate_on_update+). Each of these methods can inspect the state of the object, which usually means ensuring
266
+ # that a number of attributes have a certain value (such as not empty, within a given range, matching a certain regular expression).
267
+ #
268
+ # Example:
269
+ #
270
+ # class Person < ActiveRecord::Base
271
+ # protected
272
+ # def validate
273
+ # errors.add_on_empty %w( first_name last_name )
274
+ # errors.add("phone_number", "has invalid format") unless phone_number =~ /[0-9]*/
275
+ # end
276
+ #
277
+ # def validate_on_create # is only run the first time a new object is saved
278
+ # unless valid_discount?(membership_discount)
279
+ # errors.add("membership_discount", "has expired")
280
+ # end
281
+ # end
282
+ #
283
+ # def validate_on_update
284
+ # errors.add_to_base("No changes have occurred") if unchanged_attributes?
285
+ # end
286
+ # end
287
+ #
288
+ # person = Person.new("first_name" => "David", "phone_number" => "what?")
289
+ # person.save # => false (and doesn't do the save)
290
+ # person.errors.empty? # => false
291
+ # person.errors.count # => 2
292
+ # person.errors.on "last_name" # => "can't be empty"
293
+ # person.errors.on "phone_number" # => "has invalid format"
294
+ # person.errors.each_full { |msg| puts msg }
295
+ # # => "Last name can't be empty\n" +
296
+ # # "Phone number has invalid format"
297
+ #
298
+ # person.attributes = { "last_name" => "Heinemeier", "phone_number" => "555-555" }
299
+ # person.save # => true (and person is now saved in the database)
300
+ #
301
+ # An Errors object is automatically created for every Active Record.
302
+ module Validations
303
+ VALIDATIONS = %w( validate validate_on_create validate_on_update )
304
+
305
+ def self.included(base) # :nodoc:
306
+ base.extend ClassMethods
307
+ base.class_eval do
308
+ alias_method_chain :save, :validation
309
+ alias_method_chain :save!, :validation
310
+ end
311
+
312
+ base.send :include, ActiveSupport::Callbacks
313
+ base.define_callbacks *VALIDATIONS
314
+ end
315
+
316
+ # Active Record classes can implement validations in several ways. The highest level, easiest to read,
317
+ # and recommended approach is to use the declarative <tt>validates_..._of</tt> class methods (and
318
+ # +validates_associated+) documented below. These are sufficient for most model validations.
319
+ #
320
+ # Slightly lower level is +validates_each+. It provides some of the same options as the purely declarative
321
+ # validation methods, but like all the lower-level approaches it requires manually adding to the errors collection
322
+ # when the record is invalid.
323
+ #
324
+ # At a yet lower level, a model can use the class methods +validate+, +validate_on_create+ and +validate_on_update+
325
+ # to add validation methods or blocks. These are ActiveSupport::Callbacks and follow the same rules of inheritance
326
+ # and chaining.
327
+ #
328
+ # The lowest level style is to define the instance methods +validate+, +validate_on_create+ and +validate_on_update+
329
+ # as documented in ActiveRecord::Validations.
330
+ #
331
+ # == +validate+, +validate_on_create+ and +validate_on_update+ Class Methods
332
+ #
333
+ # Calls to these methods add a validation method or block to the class. Again, this approach is recommended
334
+ # only when the higher-level methods documented below (<tt>validates_..._of</tt> and +validates_associated+) are
335
+ # insufficient to handle the required validation.
336
+ #
337
+ # This can be done with a symbol pointing to a method:
338
+ #
339
+ # class Comment < ActiveRecord::Base
340
+ # validate :must_be_friends
341
+ #
342
+ # def must_be_friends
343
+ # errors.add_to_base("Must be friends to leave a comment") unless commenter.friend_of?(commentee)
344
+ # end
345
+ # end
346
+ #
347
+ # Or with a block which is passed the current record to be validated:
348
+ #
349
+ # class Comment < ActiveRecord::Base
350
+ # validate do |comment|
351
+ # comment.must_be_friends
352
+ # end
353
+ #
354
+ # def must_be_friends
355
+ # errors.add_to_base("Must be friends to leave a comment") unless commenter.friend_of?(commentee)
356
+ # end
357
+ # end
358
+ #
359
+ # This usage applies to +validate_on_create+ and +validate_on_update+ as well.
360
+ module ClassMethods
361
+ DEFAULT_VALIDATION_OPTIONS = {
362
+ :on => :save,
363
+ :allow_nil => false,
364
+ :allow_blank => false,
365
+ :message => nil
366
+ }.freeze
367
+
368
+ ALL_RANGE_OPTIONS = [ :is, :within, :in, :minimum, :maximum ].freeze
369
+ ALL_NUMERICALITY_CHECKS = { :greater_than => '>', :greater_than_or_equal_to => '>=',
370
+ :equal_to => '==', :less_than => '<', :less_than_or_equal_to => '<=',
371
+ :odd => 'odd?', :even => 'even?' }.freeze
372
+
373
+ # Validates each attribute against a block.
374
+ #
375
+ # class Person < ActiveRecord::Base
376
+ # validates_each :first_name, :last_name do |record, attr, value|
377
+ # record.errors.add attr, 'starts with z.' if value[0] == ?z
378
+ # end
379
+ # end
380
+ #
381
+ # Options:
382
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
383
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
384
+ # * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
385
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
386
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
387
+ # method, proc or string should return or evaluate to a true or false value.
388
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
389
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
390
+ # method, proc or string should return or evaluate to a true or false value.
391
+ def validates_each(*attrs)
392
+ options = attrs.extract_options!.symbolize_keys
393
+ attrs = attrs.flatten
394
+
395
+ # Declare the validation.
396
+ send(validation_method(options[:on] || :save), options) do |record|
397
+ attrs.each do |attr|
398
+ value = record.send(attr)
399
+ next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
400
+ yield record, attr, value
401
+ end
402
+ end
403
+ end
404
+
405
+ # Encapsulates the pattern of wanting to validate a password or email address field with a confirmation. Example:
406
+ #
407
+ # Model:
408
+ # class Person < ActiveRecord::Base
409
+ # validates_confirmation_of :user_name, :password
410
+ # validates_confirmation_of :email_address, :message => "should match confirmation"
411
+ # end
412
+ #
413
+ # View:
414
+ # <%= password_field "person", "password" %>
415
+ # <%= password_field "person", "password_confirmation" %>
416
+ #
417
+ # The added +password_confirmation+ attribute is virtual; it exists only as an in-memory attribute for validating the password.
418
+ # To achieve this, the validation adds accessors to the model for the confirmation attribute. NOTE: This check is performed
419
+ # only if +password_confirmation+ is not +nil+, and by default only on save. To require confirmation, make sure to add a presence
420
+ # check for the confirmation attribute:
421
+ #
422
+ # validates_presence_of :password_confirmation, :if => :password_changed?
423
+ #
424
+ # Configuration options:
425
+ # * <tt>:message</tt> - A custom error message (default is: "doesn't match confirmation").
426
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
427
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
428
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
429
+ # method, proc or string should return or evaluate to a true or false value.
430
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
431
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
432
+ # method, proc or string should return or evaluate to a true or false value.
433
+ def validates_confirmation_of(*attr_names)
434
+ configuration = { :on => :save }
435
+ configuration.update(attr_names.extract_options!)
436
+
437
+ attr_accessor(*(attr_names.map { |n| "#{n}_confirmation" }))
438
+
439
+ validates_each(attr_names, configuration) do |record, attr_name, value|
440
+ unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation")
441
+ record.errors.add(attr_name, :confirmation, :default => configuration[:message])
442
+ end
443
+ end
444
+ end
445
+
446
+ # Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement). Example:
447
+ #
448
+ # class Person < ActiveRecord::Base
449
+ # validates_acceptance_of :terms_of_service
450
+ # validates_acceptance_of :eula, :message => "must be abided"
451
+ # end
452
+ #
453
+ # If the database column does not exist, the +terms_of_service+ attribute is entirely virtual. This check is
454
+ # performed only if +terms_of_service+ is not +nil+ and by default on save.
455
+ #
456
+ # Configuration options:
457
+ # * <tt>:message</tt> - A custom error message (default is: "must be accepted").
458
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
459
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is true).
460
+ # * <tt>:accept</tt> - Specifies value that is considered accepted. The default value is a string "1", which
461
+ # makes it easy to relate to an HTML checkbox. This should be set to +true+ if you are validating a database
462
+ # column, since the attribute is typecast from "1" to +true+ before validation.
463
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
464
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
465
+ # method, proc or string should return or evaluate to a true or false value.
466
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
467
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
468
+ # method, proc or string should return or evaluate to a true or false value.
469
+ def validates_acceptance_of(*attr_names)
470
+ configuration = { :on => :save, :allow_nil => true, :accept => "1" }
471
+ configuration.update(attr_names.extract_options!)
472
+
473
+ db_cols = begin
474
+ column_names
475
+ rescue Exception # To ignore both statement and connection errors
476
+ []
477
+ end
478
+ names = attr_names.reject { |name| db_cols.include?(name.to_s) }
479
+ attr_accessor(*names)
480
+
481
+ validates_each(attr_names,configuration) do |record, attr_name, value|
482
+ unless value == configuration[:accept]
483
+ record.errors.add(attr_name, :accepted, :default => configuration[:message])
484
+ end
485
+ end
486
+ end
487
+
488
+ # Validates that the specified attributes are not blank (as defined by Object#blank?). Happens by default on save. Example:
489
+ #
490
+ # class Person < ActiveRecord::Base
491
+ # validates_presence_of :first_name
492
+ # end
493
+ #
494
+ # The first_name attribute must be in the object and it cannot be blank.
495
+ #
496
+ # If you want to validate the presence of a boolean field (where the real values are true and false),
497
+ # you will want to use validates_inclusion_of :field_name, :in => [true, false]
498
+ # This is due to the way Object#blank? handles boolean values. false.blank? # => true
499
+ #
500
+ # Configuration options:
501
+ # * <tt>message</tt> - A custom error message (default is: "can't be blank").
502
+ # * <tt>on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
503
+ # * <tt>if</tt> - Specifies a method, proc or string to call to determine if the validation should
504
+ # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The
505
+ # method, proc or string should return or evaluate to a true or false value.
506
+ # * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
507
+ # not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
508
+ # method, proc or string should return or evaluate to a true or false value.
509
+ #
510
+ def validates_presence_of(*attr_names)
511
+ configuration = { :on => :save }
512
+ configuration.update(attr_names.extract_options!)
513
+
514
+ # can't use validates_each here, because it cannot cope with nonexistent attributes,
515
+ # while errors.add_on_empty can
516
+ send(validation_method(configuration[:on]), configuration) do |record|
517
+ record.errors.add_on_blank(attr_names, configuration[:message])
518
+ end
519
+ end
520
+
521
+ # Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time:
522
+ #
523
+ # class Person < ActiveRecord::Base
524
+ # validates_length_of :first_name, :maximum=>30
525
+ # validates_length_of :last_name, :maximum=>30, :message=>"less than {{count}} if you don't mind"
526
+ # validates_length_of :fax, :in => 7..32, :allow_nil => true
527
+ # validates_length_of :phone, :in => 7..32, :allow_blank => true
528
+ # validates_length_of :user_name, :within => 6..20, :too_long => "pick a shorter name", :too_short => "pick a longer name"
529
+ # validates_length_of :fav_bra_size, :minimum => 1, :too_short => "please enter at least {{count}} character"
530
+ # validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with {{count}} characters... don't play me."
531
+ # validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least {{count}} words."), :tokenizer => lambda {|str| str.scan(/\w+/) }
532
+ # end
533
+ #
534
+ # Configuration options:
535
+ # * <tt>:minimum</tt> - The minimum size of the attribute.
536
+ # * <tt>:maximum</tt> - The maximum size of the attribute.
537
+ # * <tt>:is</tt> - The exact size of the attribute.
538
+ # * <tt>:within</tt> - A range specifying the minimum and maximum size of the attribute.
539
+ # * <tt>:in</tt> - A synonym(or alias) for <tt>:within</tt>.
540
+ # * <tt>:allow_nil</tt> - Attribute may be +nil+; skip validation.
541
+ # * <tt>:allow_blank</tt> - Attribute may be blank; skip validation.
542
+ # * <tt>:too_long</tt> - The error message if the attribute goes over the maximum (default is: "is too long (maximum is {{count}} characters)").
543
+ # * <tt>:too_short</tt> - The error message if the attribute goes under the minimum (default is: "is too short (min is {{count}} characters)").
544
+ # * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt> method and the attribute is the wrong size (default is: "is the wrong length (should be {{count}} characters)").
545
+ # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
546
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
547
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
548
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
549
+ # method, proc or string should return or evaluate to a true or false value.
550
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
551
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
552
+ # method, proc or string should return or evaluate to a true or false value.
553
+ # * <tt>:tokenizer</tt> - Specifies how to split up the attribute string. (e.g. <tt>:tokenizer => lambda {|str| str.scan(/\w+/)}</tt> to
554
+ # count words as in above example.)
555
+ # Defaults to <tt>lambda{ |value| value.split(//) }</tt> which counts individual characters.
556
+ def validates_length_of(*attrs)
557
+ # Merge given options with defaults.
558
+ options = {
559
+ :tokenizer => lambda {|value| value.split(//)}
560
+ }.merge(DEFAULT_VALIDATION_OPTIONS)
561
+ options.update(attrs.extract_options!.symbolize_keys)
562
+
563
+ # Ensure that one and only one range option is specified.
564
+ range_options = ALL_RANGE_OPTIONS & options.keys
565
+ case range_options.size
566
+ when 0
567
+ raise ArgumentError, 'Range unspecified. Specify the :within, :maximum, :minimum, or :is option.'
568
+ when 1
569
+ # Valid number of options; do nothing.
570
+ else
571
+ raise ArgumentError, 'Too many range options specified. Choose only one.'
572
+ end
573
+
574
+ # Get range option and value.
575
+ option = range_options.first
576
+ option_value = options[range_options.first]
577
+
578
+ case option
579
+ when :within, :in
580
+ raise ArgumentError, ":#{option} must be a Range" unless option_value.is_a?(Range)
581
+
582
+ validates_each(attrs, options) do |record, attr, value|
583
+ value = options[:tokenizer].call(value) if value.kind_of?(String)
584
+ if value.nil? or value.size < option_value.begin
585
+ record.errors.add(attr, :too_short, :default => options[:too_short], :count => option_value.begin)
586
+ elsif value.size > option_value.end
587
+ record.errors.add(attr, :too_long, :default => options[:too_long], :count => option_value.end)
588
+ end
589
+ end
590
+ when :is, :minimum, :maximum
591
+ raise ArgumentError, ":#{option} must be a nonnegative Integer" unless option_value.is_a?(Integer) and option_value >= 0
592
+
593
+ # Declare different validations per option.
594
+ validity_checks = { :is => "==", :minimum => ">=", :maximum => "<=" }
595
+ message_options = { :is => :wrong_length, :minimum => :too_short, :maximum => :too_long }
596
+
597
+ validates_each(attrs, options) do |record, attr, value|
598
+ value = options[:tokenizer].call(value) if value.kind_of?(String)
599
+ unless !value.nil? and value.size.method(validity_checks[option])[option_value]
600
+ key = message_options[option]
601
+ custom_message = options[:message] || options[key]
602
+ record.errors.add(attr, key, :default => custom_message, :count => option_value)
603
+ end
604
+ end
605
+ end
606
+ end
607
+
608
+ alias_method :validates_size_of, :validates_length_of
609
+
610
+
611
+ # Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user
612
+ # can be named "davidhh".
613
+ #
614
+ # class Person < ActiveRecord::Base
615
+ # validates_uniqueness_of :user_name, :scope => :account_id
616
+ # end
617
+ #
618
+ # It can also validate whether the value of the specified attributes are unique based on multiple scope parameters. For example,
619
+ # making sure that a teacher can only be on the schedule once per semester for a particular class.
620
+ #
621
+ # class TeacherSchedule < ActiveRecord::Base
622
+ # validates_uniqueness_of :teacher_id, :scope => [:semester_id, :class_id]
623
+ # end
624
+ #
625
+ # When the record is created, a check is performed to make sure that no record exists in the database with the given value for the specified
626
+ # attribute (that maps to a column). When the record is updated, the same check is made but disregarding the record itself.
627
+ #
628
+ # Configuration options:
629
+ # * <tt>:message</tt> - Specifies a custom error message (default is: "has already been taken").
630
+ # * <tt>:scope</tt> - One or more columns by which to limit the scope of the uniqueness constraint.
631
+ # * <tt>:case_sensitive</tt> - Looks for an exact match. Ignored by non-text columns (+true+ by default).
632
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
633
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
634
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
635
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
636
+ # method, proc or string should return or evaluate to a true or false value.
637
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
638
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
639
+ # method, proc or string should return or evaluate to a true or false value.
640
+ #
641
+ # === Concurrency and integrity
642
+ #
643
+ # Using this validation method in conjunction with ActiveRecord::Base#save
644
+ # does not guarantee the absence of duplicate record insertions, because
645
+ # uniqueness checks on the application level are inherently prone to race
646
+ # conditions. For example, suppose that two users try to post a Comment at
647
+ # the same time, and a Comment's title must be unique. At the database-level,
648
+ # the actions performed by these users could be interleaved in the following manner:
649
+ #
650
+ # User 1 | User 2
651
+ # ------------------------------------+--------------------------------------
652
+ # # User 1 checks whether there's |
653
+ # # already a comment with the title |
654
+ # # 'My Post'. This is not the case. |
655
+ # SELECT * FROM comments |
656
+ # WHERE title = 'My Post' |
657
+ # |
658
+ # | # User 2 does the same thing and also
659
+ # | # infers that his title is unique.
660
+ # | SELECT * FROM comments
661
+ # | WHERE title = 'My Post'
662
+ # |
663
+ # # User 1 inserts his comment. |
664
+ # INSERT INTO comments |
665
+ # (title, content) VALUES |
666
+ # ('My Post', 'hi!') |
667
+ # |
668
+ # | # User 2 does the same thing.
669
+ # | INSERT INTO comments
670
+ # | (title, content) VALUES
671
+ # | ('My Post', 'hello!')
672
+ # |
673
+ # | # ^^^^^^
674
+ # | # Boom! We now have a duplicate
675
+ # | # title!
676
+ #
677
+ # This could even happen if you use transactions with the 'serializable'
678
+ # isolation level. There are several ways to get around this problem:
679
+ # - By locking the database table before validating, and unlocking it after
680
+ # saving. However, table locking is very expensive, and thus not
681
+ # recommended.
682
+ # - By locking a lock file before validating, and unlocking it after saving.
683
+ # This does not work if you've scaled your Rails application across
684
+ # multiple web servers (because they cannot share lock files, or cannot
685
+ # do that efficiently), and thus not recommended.
686
+ # - Creating a unique index on the field, by using
687
+ # ActiveRecord::ConnectionAdapters::SchemaStatements#add_index. In the
688
+ # rare case that a race condition occurs, the database will guarantee
689
+ # the field's uniqueness.
690
+ #
691
+ # When the database catches such a duplicate insertion,
692
+ # ActiveRecord::Base#save will raise an ActiveRecord::StatementInvalid
693
+ # exception. You can either choose to let this error propagate (which
694
+ # will result in the default Rails exception page being shown), or you
695
+ # can catch it and restart the transaction (e.g. by telling the user
696
+ # that the title already exists, and asking him to re-enter the title).
697
+ # This technique is also known as optimistic concurrency control:
698
+ # http://en.wikipedia.org/wiki/Optimistic_concurrency_control
699
+ #
700
+ # Active Record currently provides no way to distinguish unique
701
+ # index constraint errors from other types of database errors, so you
702
+ # will have to parse the (database-specific) exception message to detect
703
+ # such a case.
704
+ def validates_uniqueness_of(*attr_names)
705
+ configuration = { :case_sensitive => true }
706
+ configuration.update(attr_names.extract_options!)
707
+
708
+ validates_each(attr_names,configuration) do |record, attr_name, value|
709
+ # The check for an existing value should be run from a class that
710
+ # isn't abstract. This means working down from the current class
711
+ # (self), to the first non-abstract class. Since classes don't know
712
+ # their subclasses, we have to build the hierarchy between self and
713
+ # the record's class.
714
+ class_hierarchy = [record.class]
715
+ while class_hierarchy.first != self
716
+ class_hierarchy.insert(0, class_hierarchy.first.superclass)
717
+ end
718
+
719
+ # Now we can work our way down the tree to the first non-abstract
720
+ # class (which has a database table to query from).
721
+ finder_class = class_hierarchy.detect { |klass| !klass.abstract_class? }
722
+
723
+ is_text_column = finder_class.columns_hash[attr_name.to_s].text?
724
+
725
+ if value.nil?
726
+ comparison_operator = "IS ?"
727
+ elsif is_text_column
728
+ comparison_operator = "#{connection.case_sensitive_equality_operator} ?"
729
+ value = value.to_s
730
+ else
731
+ comparison_operator = "= ?"
732
+ end
733
+
734
+ sql_attribute = "#{record.class.quoted_table_name}.#{connection.quote_column_name(attr_name)}"
735
+
736
+ if value.nil? || (configuration[:case_sensitive] || !is_text_column)
737
+ condition_sql = "#{sql_attribute} #{comparison_operator}"
738
+ condition_params = [value]
739
+ else
740
+ condition_sql = "LOWER(#{sql_attribute}) #{comparison_operator}"
741
+ condition_params = [value.mb_chars.downcase]
742
+ end
743
+
744
+ if scope = configuration[:scope]
745
+ Array(scope).map do |scope_item|
746
+ scope_value = record.send(scope_item)
747
+ condition_sql << " AND #{record.class.quoted_table_name}.#{scope_item} #{attribute_condition(scope_value)}"
748
+ condition_params << scope_value
749
+ end
750
+ end
751
+
752
+ unless record.new_record?
753
+ condition_sql << " AND #{record.class.quoted_table_name}.#{record.class.primary_key} <> ?"
754
+ condition_params << record.send(:id)
755
+ end
756
+
757
+ finder_class.with_exclusive_scope do
758
+ if finder_class.exists?([condition_sql, *condition_params])
759
+ record.errors.add(attr_name, :taken, :default => configuration[:message], :value => value)
760
+ end
761
+ end
762
+ end
763
+ end
764
+
765
+
766
+ # Validates whether the value of the specified attribute is of the correct form by matching it against the regular expression
767
+ # provided.
768
+ #
769
+ # class Person < ActiveRecord::Base
770
+ # validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
771
+ # end
772
+ #
773
+ # Note: use <tt>\A</tt> and <tt>\Z</tt> to match the start and end of the string, <tt>^</tt> and <tt>$</tt> match the start/end of a line.
774
+ #
775
+ # A regular expression must be provided or else an exception will be raised.
776
+ #
777
+ # Configuration options:
778
+ # * <tt>:message</tt> - A custom error message (default is: "is invalid").
779
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
780
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
781
+ # * <tt>:with</tt> - The regular expression used to validate the format with (note: must be supplied!).
782
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
783
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
784
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
785
+ # method, proc or string should return or evaluate to a true or false value.
786
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
787
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
788
+ # method, proc or string should return or evaluate to a true or false value.
789
+ def validates_format_of(*attr_names)
790
+ configuration = { :on => :save, :with => nil }
791
+ configuration.update(attr_names.extract_options!)
792
+
793
+ raise(ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash") unless configuration[:with].is_a?(Regexp)
794
+
795
+ validates_each(attr_names, configuration) do |record, attr_name, value|
796
+ unless value.to_s =~ configuration[:with]
797
+ record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
798
+ end
799
+ end
800
+ end
801
+
802
+ # Validates whether the value of the specified attribute is available in a particular enumerable object.
803
+ #
804
+ # class Person < ActiveRecord::Base
805
+ # validates_inclusion_of :gender, :in => %w( m f ), :message => "woah! what are you then!??!!"
806
+ # validates_inclusion_of :age, :in => 0..99
807
+ # validates_inclusion_of :format, :in => %w( jpg gif png ), :message => "extension {{value}} is not included in the list"
808
+ # end
809
+ #
810
+ # Configuration options:
811
+ # * <tt>:in</tt> - An enumerable object of available items.
812
+ # * <tt>:message</tt> - Specifies a custom error message (default is: "is not included in the list").
813
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
814
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
815
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
816
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
817
+ # method, proc or string should return or evaluate to a true or false value.
818
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
819
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
820
+ # method, proc or string should return or evaluate to a true or false value.
821
+ def validates_inclusion_of(*attr_names)
822
+ configuration = { :on => :save }
823
+ configuration.update(attr_names.extract_options!)
824
+
825
+ enum = configuration[:in] || configuration[:within]
826
+
827
+ raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)
828
+
829
+ validates_each(attr_names, configuration) do |record, attr_name, value|
830
+ unless enum.include?(value)
831
+ record.errors.add(attr_name, :inclusion, :default => configuration[:message], :value => value)
832
+ end
833
+ end
834
+ end
835
+
836
+ # Validates that the value of the specified attribute is not in a particular enumerable object.
837
+ #
838
+ # class Person < ActiveRecord::Base
839
+ # validates_exclusion_of :username, :in => %w( admin superuser ), :message => "You don't belong here"
840
+ # validates_exclusion_of :age, :in => 30..60, :message => "This site is only for under 30 and over 60"
841
+ # validates_exclusion_of :format, :in => %w( mov avi ), :message => "extension {{value}} is not allowed"
842
+ # end
843
+ #
844
+ # Configuration options:
845
+ # * <tt>:in</tt> - An enumerable object of items that the value shouldn't be part of.
846
+ # * <tt>:message</tt> - Specifies a custom error message (default is: "is reserved").
847
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
848
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
849
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
850
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
851
+ # method, proc or string should return or evaluate to a true or false value.
852
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
853
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
854
+ # method, proc or string should return or evaluate to a true or false value.
855
+ def validates_exclusion_of(*attr_names)
856
+ configuration = { :on => :save }
857
+ configuration.update(attr_names.extract_options!)
858
+
859
+ enum = configuration[:in] || configuration[:within]
860
+
861
+ raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)
862
+
863
+ validates_each(attr_names, configuration) do |record, attr_name, value|
864
+ if enum.include?(value)
865
+ record.errors.add(attr_name, :exclusion, :default => configuration[:message], :value => value)
866
+ end
867
+ end
868
+ end
869
+
870
+ # Validates whether the associated object or objects are all valid themselves. Works with any kind of association.
871
+ #
872
+ # class Book < ActiveRecord::Base
873
+ # has_many :pages
874
+ # belongs_to :library
875
+ #
876
+ # validates_associated :pages, :library
877
+ # end
878
+ #
879
+ # Warning: If, after the above definition, you then wrote:
880
+ #
881
+ # class Page < ActiveRecord::Base
882
+ # belongs_to :book
883
+ #
884
+ # validates_associated :book
885
+ # end
886
+ #
887
+ # this would specify a circular dependency and cause infinite recursion.
888
+ #
889
+ # NOTE: This validation will not fail if the association hasn't been assigned. If you want to ensure that the association
890
+ # is both present and guaranteed to be valid, you also need to use +validates_presence_of+.
891
+ #
892
+ # Configuration options:
893
+ # * <tt>:message</tt> - A custom error message (default is: "is invalid")
894
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
895
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
896
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
897
+ # method, proc or string should return or evaluate to a true or false value.
898
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
899
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
900
+ # method, proc or string should return or evaluate to a true or false value.
901
+ def validates_associated(*attr_names)
902
+ configuration = { :on => :save }
903
+ configuration.update(attr_names.extract_options!)
904
+
905
+ validates_each(attr_names, configuration) do |record, attr_name, value|
906
+ unless (value.is_a?(Array) ? value : [value]).inject(true) { |v, r| (r.nil? || r.valid?) && v }
907
+ record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
908
+ end
909
+ end
910
+ end
911
+
912
+ # Validates whether the value of the specified attribute is numeric by trying to convert it to
913
+ # a float with Kernel.Float (if <tt>only_integer</tt> is false) or applying it to the regular expression
914
+ # <tt>/\A[\+\-]?\d+\Z/</tt> (if <tt>only_integer</tt> is set to true).
915
+ #
916
+ # class Person < ActiveRecord::Base
917
+ # validates_numericality_of :value, :on => :create
918
+ # end
919
+ #
920
+ # Configuration options:
921
+ # * <tt>:message</tt> - A custom error message (default is: "is not a number").
922
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
923
+ # * <tt>:only_integer</tt> - Specifies whether the value has to be an integer, e.g. an integral value (default is +false+).
924
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is +false+). Notice that for fixnum and float columns empty strings are converted to +nil+.
925
+ # * <tt>:greater_than</tt> - Specifies the value must be greater than the supplied value.
926
+ # * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be greater than or equal the supplied value.
927
+ # * <tt>:equal_to</tt> - Specifies the value must be equal to the supplied value.
928
+ # * <tt>:less_than</tt> - Specifies the value must be less than the supplied value.
929
+ # * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less than or equal the supplied value.
930
+ # * <tt>:odd</tt> - Specifies the value must be an odd number.
931
+ # * <tt>:even</tt> - Specifies the value must be an even number.
932
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
933
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
934
+ # method, proc or string should return or evaluate to a true or false value.
935
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
936
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
937
+ # method, proc or string should return or evaluate to a true or false value.
938
+ def validates_numericality_of(*attr_names)
939
+ configuration = { :on => :save, :only_integer => false, :allow_nil => false }
940
+ configuration.update(attr_names.extract_options!)
941
+
942
+
943
+ numericality_options = ALL_NUMERICALITY_CHECKS.keys & configuration.keys
944
+
945
+ (numericality_options - [ :odd, :even ]).each do |option|
946
+ raise ArgumentError, ":#{option} must be a number" unless configuration[option].is_a?(Numeric)
947
+ end
948
+
949
+ validates_each(attr_names,configuration) do |record, attr_name, value|
950
+ raw_value = record.send("#{attr_name}_before_type_cast") || value
951
+
952
+ next if configuration[:allow_nil] and raw_value.nil?
953
+
954
+ if configuration[:only_integer]
955
+ unless raw_value.to_s =~ /\A[+-]?\d+\Z/
956
+ record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
957
+ next
958
+ end
959
+ raw_value = raw_value.to_i
960
+ else
961
+ begin
962
+ raw_value = Kernel.Float(raw_value)
963
+ rescue ArgumentError, TypeError
964
+ record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
965
+ next
966
+ end
967
+ end
968
+
969
+ numericality_options.each do |option|
970
+ case option
971
+ when :odd, :even
972
+ unless raw_value.to_i.method(ALL_NUMERICALITY_CHECKS[option])[]
973
+ record.errors.add(attr_name, option, :value => raw_value, :default => configuration[:message])
974
+ end
975
+ else
976
+ record.errors.add(attr_name, option, :default => configuration[:message], :value => raw_value, :count => configuration[option]) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]
977
+ end
978
+ end
979
+ end
980
+ end
981
+
982
+ # Creates an object just like Base.create but calls save! instead of save
983
+ # so an exception is raised if the record is invalid.
984
+ def create!(attributes = nil, &block)
985
+ if attributes.is_a?(Array)
986
+ attributes.collect { |attr| create!(attr, &block) }
987
+ else
988
+ object = new(attributes)
989
+ yield(object) if block_given?
990
+ object.save!
991
+ object
992
+ end
993
+ end
994
+
995
+ private
996
+ def validation_method(on)
997
+ case on
998
+ when :save then :validate
999
+ when :create then :validate_on_create
1000
+ when :update then :validate_on_update
1001
+ end
1002
+ end
1003
+ end
1004
+
1005
+ # The validation process on save can be skipped by passing false. The regular Base#save method is
1006
+ # replaced with this when the validations module is mixed in, which it is by default.
1007
+ def save_with_validation(perform_validation = true)
1008
+ if perform_validation && valid? || !perform_validation
1009
+ save_without_validation
1010
+ else
1011
+ false
1012
+ end
1013
+ end
1014
+
1015
+ # Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false
1016
+ # if the record is not valid.
1017
+ def save_with_validation!
1018
+ if valid?
1019
+ save_without_validation!
1020
+ else
1021
+ raise RecordInvalid.new(self)
1022
+ end
1023
+ end
1024
+
1025
+ # Runs +validate+ and +validate_on_create+ or +validate_on_update+ and returns true if no errors were added otherwise false.
1026
+ def valid?
1027
+ errors.clear
1028
+
1029
+ run_callbacks(:validate)
1030
+ validate
1031
+
1032
+ if new_record?
1033
+ run_callbacks(:validate_on_create)
1034
+ validate_on_create
1035
+ else
1036
+ run_callbacks(:validate_on_update)
1037
+ validate_on_update
1038
+ end
1039
+
1040
+ errors.empty?
1041
+ end
1042
+
1043
+ # Returns the Errors object that holds all information about attribute error messages.
1044
+ def errors
1045
+ @errors ||= Errors.new(self)
1046
+ end
1047
+
1048
+ protected
1049
+ # Overwrite this method for validation checks on all saves and use <tt>Errors.add(field, msg)</tt> for invalid attributes.
1050
+ def validate #:doc:
1051
+ end
1052
+
1053
+ # Overwrite this method for validation checks used only on creation.
1054
+ def validate_on_create #:doc:
1055
+ end
1056
+
1057
+ # Overwrite this method for validation checks used only on updates.
1058
+ def validate_on_update # :doc:
1059
+ end
1060
+ end
1061
+ end