Module: SimpleRecord::Validations
- Included in:
- Base
- Defined in:
- lib/simple_record/validations.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
if defined?(:valid?) # from ActiveModel alias_method :am_valid?, :valid? end.
Instance Method Summary collapse
- #invalid? ⇒ Boolean
- #read_attribute_for_validation(key) ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
- #validate_on_create ⇒ Object
- #validate_on_update ⇒ Object
Class Method Details
.included(base) ⇒ Object
if defined?(:valid?) # from ActiveModel
alias_method :am_valid?, :valid?
end
11 12 13 14 15 16 17 18 |
# File 'lib/simple_record/validations.rb', line 11 def self.included(base) puts 'Validations included ' + base.inspect # if defined?(ActiveModel) # base.class_eval do # alias_method :am_valid?, :valid? # end # end end |
Instance Method Details
#invalid? ⇒ Boolean
45 46 47 |
# File 'lib/simple_record/validations.rb', line 45 def invalid? !valid? end |
#read_attribute_for_validation(key) ⇒ Object
50 51 52 |
# File 'lib/simple_record/validations.rb', line 50 def read_attribute_for_validation(key) @attributes[key.to_s] end |
#valid? ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/simple_record/validations.rb', line 20 def valid? # puts 'in rails2 valid?' errors.clear if respond_to?(:am_valid?) # And now ActiveModel validations too am_valid? end # run_callbacks(:validate) validate if new_record? # run_callbacks(:validate_on_create) validate_on_create else # run_callbacks(:validate_on_update) validate_on_update end errors.empty? end |
#validate ⇒ Object
54 55 56 |
# File 'lib/simple_record/validations.rb', line 54 def validate true end |
#validate_on_create ⇒ Object
58 59 60 |
# File 'lib/simple_record/validations.rb', line 58 def validate_on_create true end |
#validate_on_update ⇒ Object
62 63 64 |
# File 'lib/simple_record/validations.rb', line 62 def validate_on_update true end |