Module: Koujou::ActiveRecordExtensions::ValidationReflection::ClassMethods
- Defined in:
- lib/koujou/validation_reflection.rb
Instance Method Summary collapse
- #confirmation_validations ⇒ Object
- #custom_validations ⇒ Object
- #inclusion_validations ⇒ Object
- #length_validations ⇒ Object
-
#reflect_on_all_validations ⇒ Object
Returns an array of MacroReflection objects for all validations in the class.
-
#reflect_on_validations_for(attr_name) ⇒ Object
Returns an array of MacroReflection objects for all validations defined for the field
attr_name
. - #required_validations ⇒ Object
-
#unique_validations ⇒ Object
A few convenience methods added in by Mike.
Instance Method Details
#confirmation_validations ⇒ Object
103 104 105 |
# File 'lib/koujou/validation_reflection.rb', line 103 def confirmation_validations reflect_on_all_validations.select{|v| v.macro == :validates_confirmation_of } end |
#custom_validations ⇒ Object
115 116 117 118 |
# File 'lib/koujou/validation_reflection.rb', line 115 def custom_validations # We don't want to get anything like: validate_associated_records_for_posts. reflect_on_all_validations.select{|v| v.macro == :validate && v.name.to_s.match("_associated_").nil? } end |
#inclusion_validations ⇒ Object
111 112 113 |
# File 'lib/koujou/validation_reflection.rb', line 111 def inclusion_validations reflect_on_all_validations.select{|v| v.macro == :validates_inclusion_of } end |
#length_validations ⇒ Object
107 108 109 |
# File 'lib/koujou/validation_reflection.rb', line 107 def length_validations reflect_on_all_validations.select{|v| v.macro == :validates_length_of || v.macro == :validates_size_of } end |
#reflect_on_all_validations ⇒ Object
Returns an array of MacroReflection objects for all validations in the class
81 82 83 |
# File 'lib/koujou/validation_reflection.rb', line 81 def reflect_on_all_validations read_inheritable_attribute(:validations) || [] end |
#reflect_on_validations_for(attr_name) ⇒ Object
Returns an array of MacroReflection objects for all validations defined for the field attr_name
.
86 87 88 89 90 91 |
# File 'lib/koujou/validation_reflection.rb', line 86 def reflect_on_validations_for(attr_name) attr_name = attr_name.to_sym reflect_on_all_validations.select do |reflection| reflection.name == attr_name end end |
#required_validations ⇒ Object
99 100 101 |
# File 'lib/koujou/validation_reflection.rb', line 99 def required_validations reflect_on_all_validations.select{|v| v.macro == :validates_presence_of } end |
#unique_validations ⇒ Object
A few convenience methods added in by Mike. Why not loop and define_method these?
95 96 97 |
# File 'lib/koujou/validation_reflection.rb', line 95 def unique_validations reflect_on_all_validations.select{|v| v.macro == :validates_uniqueness_of } end |