Module: ValidationGroup::ActiveRecord::ActsMethods
- Defined in:
- lib/validation_group.rb
Overview
extends ActiveRecord::Base
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.extended(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/validation_group.rb', line 4 def self.extended(base) # Add class accessor which is shared between all models and stores # validation groups defined for each model base.class_eval do cattr_accessor :validation_group_classes self.validation_group_classes = {} def self.validation_group_order; @validation_group_order; end def self.validation_groups(all_classes = false) return (self.validation_group_classes[self] || {}) unless all_classes klasses = ValidationGroup::Util.current_and_ancestors(self).reverse returning Hash.new do |hash| klasses.each do |klass| hash.merge! self.validation_group_classes[klass] end end end end end |
Instance Method Details
#validation_group(name, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/validation_group.rb', line 24 def validation_group(name, ={}) self_groups = (self.validation_group_classes[self] ||= {}) self_groups[name.to_sym] = case [:fields] when Array then [:fields] when Symbol, String then [[:fields].to_sym] else [] end # jeffp: capture the declaration order for this class only (no # superclasses) (@validation_group_order ||= []) << name.to_sym unless included_modules.include?(InstanceMethods) # jeffp: added reader for current_validation_fields attr_reader :current_validation_group, :current_validation_fields include InstanceMethods # jeffp: add valid?(group = nil), see definition below alias_method_chain :valid?, :validation_group end end |