Module: Dynamoid::Validations
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Validations, ActiveModel::Validations::Callbacks
- Included in:
- Components
- Defined in:
- lib/dynamoid/validations.rb
Overview
Provide ActiveModel validations to Dynamoid documents.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#save(options = {}) ⇒ Object
Override save to provide validation support.
-
#save! ⇒ Object
Raise an error unless this object is valid.
- #update_attribute(attribute, value) ⇒ Object
-
#valid?(context = nil) ⇒ Boolean
Is this object valid?.
Instance Method Details
#save(options = {}) ⇒ Object
Override save to provide validation support.
15 16 17 18 19 20 |
# File 'lib/dynamoid/validations.rb', line 15 def save( = {}) .reverse_merge!(validate: true) return false if [:validate] && !valid? super end |
#save! ⇒ Object
Raise an error unless this object is valid.
34 35 36 37 38 39 |
# File 'lib/dynamoid/validations.rb', line 34 def save! raise Dynamoid::Errors::DocumentNotValid, self unless valid? save(validate: false) self end |
#update_attribute(attribute, value) ⇒ Object
41 42 43 44 45 |
# File 'lib/dynamoid/validations.rb', line 41 def update_attribute(attribute, value) write_attribute(attribute, value) save(validate: false) self end |
#valid?(context = nil) ⇒ Boolean
Is this object valid?
25 26 27 28 |
# File 'lib/dynamoid/validations.rb', line 25 def valid?(context = nil) context ||= (new_record? ? :create : :update) super(context) end |