grouped_validations 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,14 +35,6 @@ module GroupedValidations
35
35
  end
36
36
  end
37
37
 
38
- def group_valid?(group)
39
- raise "Validation group '#{group}' not defined" unless validation_groups.include?(group)
40
-
41
- errors.clear
42
- run_group_validation_callbacks group
43
- errors.empty?
44
- end
45
-
46
38
  def groups_valid?(*groups)
47
39
  errors.clear
48
40
  groups.each do |group|
@@ -51,14 +43,7 @@ module GroupedValidations
51
43
  end
52
44
  errors.empty?
53
45
  end
54
-
55
- def valid_with_groups?
56
- valid_without_groups?
57
- (validation_groups || []).each do |group|
58
- run_group_validation_callbacks group
59
- end
60
- errors.empty?
61
- end
46
+ alias group_valid? groups_valid?
62
47
 
63
48
  end
64
49
 
@@ -3,7 +3,7 @@ module GroupedValidations
3
3
  module ClassMethods
4
4
 
5
5
  def define_group_validation_callbacks(group)
6
- define_callbacks :"validate_#{group}", :scope => 'validate'
6
+ define_callbacks :"validate_#{group}", :terminator => "result == false", :scope => 'validate'
7
7
  end
8
8
 
9
9
  def validate_with_groups(*args, &block)
@@ -11,7 +11,7 @@ module GroupedValidations
11
11
  options = args.last
12
12
  if options.is_a?(Hash) && options.key?(:on)
13
13
  options[:if] = Array(options[:if])
14
- options[:if] << "@_on_validate == :#{options[:on]}"
14
+ options[:if] << "self.validation_context == :#{options[:on]}"
15
15
  end
16
16
  set_callback(:"validate_#{@current_validation_group}", *args, &block)
17
17
  else
@@ -23,9 +23,19 @@ module GroupedValidations
23
23
 
24
24
  module InstanceMethods
25
25
 
26
+ def valid_with_groups?(context=nil)
27
+ valid_without_groups?(context)
28
+ (validation_groups || []).each do |group|
29
+ run_group_validation_callbacks group
30
+ end
31
+ errors.empty?
32
+ end
33
+
26
34
  def run_group_validation_callbacks(group)
27
- @_on_validate = new_record? ? :create : :update
35
+ current_context, self.validation_context = validation_context, (new_record? ? :create : :update)
28
36
  send(:"_run_validate_#{group}_callbacks")
37
+ ensure
38
+ self.validation_context = current_context
29
39
  end
30
40
 
31
41
  end
@@ -24,6 +24,14 @@ module GroupedValidations
24
24
 
25
25
  module InstanceMethods
26
26
 
27
+ def valid_with_groups?
28
+ valid_without_groups?
29
+ (validation_groups || []).each do |group|
30
+ run_group_validation_callbacks group
31
+ end
32
+ errors.empty?
33
+ end
34
+
27
35
  def run_group_validation_callbacks(group)
28
36
  base_name = :"validate_#{group}"
29
37
  run_callbacks(base_name)
@@ -1,3 +1,3 @@
1
1
  module GroupedValidations
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grouped_validations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan
@@ -15,7 +15,7 @@ autorequire: grouped_validations
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-08 00:00:00 +10:00
18
+ date: 2010-08-10 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies: []
21
21