validatable 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,28 @@
1
1
  module Validatable
2
2
  module Macros
3
+ # call-seq: validates_each(*args)
4
+ #
5
+ # Validates that the logic evaluates to true
6
+ #
7
+ # class Address
8
+ # include Validatable
9
+ # validates_each :zip_code, :logic => lambda { errors.add(:zip_code, "is not valid") if ZipCodeService.allows(zip_code) }
10
+ # end
11
+ #
12
+ # The logic option is required.
13
+ #
14
+ # Configuration options:
15
+ #
16
+ # * message - The message to add to the errors collection when the validation fails
17
+ # * times - The number of times the validation applies
18
+ # * level - The level at which the validation should occur
19
+ # * if - A block that when executed must return true of the validation will not occur
20
+ # * group - The group that this validation belongs to. A validation can belong to multiple groups
21
+ # * logic - A block that executes to perform the validation def validates_each(*args)
22
+ def validates_each(*args)
23
+ add_validations(args, ValidatesEach)
24
+ end
25
+
3
26
  # call-seq: validates_format_of(*args)
4
27
  #
5
28
  # Validates whether the value of the specified attribute is of the
@@ -14,6 +14,7 @@ require File.expand_path(File.dirname(__FILE__) + '/validations/validates_confir
14
14
  require File.expand_path(File.dirname(__FILE__) + '/validations/validates_length_of')
15
15
  require File.expand_path(File.dirname(__FILE__) + '/validations/validates_true_for')
16
16
  require File.expand_path(File.dirname(__FILE__) + '/validations/validates_numericality_of')
17
+ require File.expand_path(File.dirname(__FILE__) + '/validations/validates_each')
17
18
  require File.expand_path(File.dirname(__FILE__) + '/validation_assertion')
18
19
  require File.expand_path(File.dirname(__FILE__) + '/validation_assertion_collector')
19
20
  require File.expand_path(File.dirname(__FILE__) + '/validatable_assertions')
@@ -0,0 +1,14 @@
1
+ module Validatable
2
+ class ValidatesEach < ValidationBase #:nodoc:
3
+ required_option :logic
4
+
5
+ def valid?(instance)
6
+ instance.instance_eval(&logic)
7
+ true # return true so no error is added. should look in the future at doing this different.
8
+ end
9
+
10
+ def message(instance)
11
+ super || "is invalid"
12
+ end
13
+ end
14
+ end
@@ -29,7 +29,7 @@ Gem::manage_gems
29
29
  specification = Gem::Specification.new do |s|
30
30
  s.name = "validatable"
31
31
  s.summary = "Validatable is a library for adding validations."
32
- s.version = "1.6.1"
32
+ s.version = "1.6.2"
33
33
  s.author = 'Jay Fields'
34
34
  s.description = "Validatable is a library for adding validations."
35
35
  s.email = 'validatable-developer@rubyforge.org'
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ functional_tests do
4
+ expect :is_set do
5
+ klass = Class.new do
6
+ include Validatable
7
+ attr_accessor :name, :result
8
+ validates_each :name, :logic => lambda { @result = :is_set }
9
+ end
10
+ instance = klass.new
11
+ instance.valid?
12
+ instance.result
13
+ end
14
+ end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: validatable
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.6.1
6
+ version: 1.6.2
7
7
  date: 2007-08-15 00:00:00 -04:00
8
8
  summary: Validatable is a library for adding validations.
9
9
  require_paths:
@@ -42,6 +42,7 @@ files:
42
42
  - lib/validation_assertion_collector.rb
43
43
  - lib/validations/validates_acceptance_of.rb
44
44
  - lib/validations/validates_confirmation_of.rb
45
+ - lib/validations/validates_each.rb
45
46
  - lib/validations/validates_format_of.rb
46
47
  - lib/validations/validates_length_of.rb
47
48
  - lib/validations/validates_numericality_of.rb
@@ -54,6 +55,7 @@ files:
54
55
  - test/functional/validatable_test.rb
55
56
  - test/functional/validates_acceptance_of_test.rb
56
57
  - test/functional/validates_confirmation_of_test.rb
58
+ - test/functional/validates_each_test.rb
57
59
  - test/functional/validates_format_of_test.rb
58
60
  - test/functional/validates_length_of_test.rb
59
61
  - test/functional/validates_numericality_of_test.rb