Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ source "http://rubygems.org"

gem 'rake', '~> 0.8.7'
gem 'rspec', '~> 2.4.0'
gem 'activesupport', '~> 3.2.0'
gem 'activemodel', '~> 3.2.0'
gem 'activesupport'
gem 'activemodel'
# gem 'ruby-debug'
10 changes: 6 additions & 4 deletions lib/grouped_validations.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_model/validations'
require 'grouped_validations/active_model'
require 'grouped_validations/callback'

module GroupedValidations
extend ActiveSupport::Concern
Expand Down Expand Up @@ -29,7 +30,7 @@ def validate(*args, &block)
end

def _define_group_validation_callbacks(group)
define_callbacks :"validate_#{group}", :scope => 'validate'
define_callbacks :"validate_#{group}", :scope => :callback_method, callback_method: :validate
end

end
Expand All @@ -45,6 +46,7 @@ def valid?(context=nil)
def groups_valid?(*groups)
options = groups.extract_options!
errors.clear
run_validations!
groups.each do |group|
raise "Validation group '#{group}' not defined" unless validation_groups.include?(group)
_run_group_validation_callbacks(group, options[:context])
Expand All @@ -59,12 +61,12 @@ def grouped_errors(context=nil)
grouped = {}

with_validation_context(context) do
_run_validate_callbacks
run_callbacks(:validate)
grouped[nil] = errors

validation_groups.each do |group|
@errors = nil
send(:"_run_validate_#{group}_callbacks")
run_callbacks(:"validate_#{group}")
grouped[group] = errors
end
end
Expand All @@ -75,7 +77,7 @@ def grouped_errors(context=nil)

def _run_group_validation_callbacks(group, context=nil)
with_validation_context(context) do
send(:"_run_validate_#{group}_callbacks")
run_callbacks(:"validate_#{group}")
end
end

Expand Down
5 changes: 5 additions & 0 deletions lib/grouped_validations/callback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ActiveSupport::Callbacks::Callback
def callback_method
chain_config[:callback_method]
end
end