Module: Neo4j::Rails::Validations
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Validations
- Included in:
- Model, Relationship
- Defined in:
- lib/neo4j/rails/validations.rb,
lib/neo4j/rails/validations/non_nil.rb,
lib/neo4j/rails/validations/uniqueness.rb,
lib/neo4j/rails/validations/associated.rb
Overview
This mixin replace the original save method and performs validation before the save.
Defined Under Namespace
Modules: ClassMethods Classes: AssociatedValidator, ExactMatchValidator, FulltextMatchValidator, NonNilValidator, UniquenessValidator
Instance Method Summary (collapse)
-
- (Object) read_attribute_for_validation(key)
Implements the ActiveModel::Validation hook method.
-
- (Boolean) save(options = {})
The validation process on save can be skipped by passing false.
-
- (Boolean) valid?(context = nil)
True if valid.
Instance Method Details
- (Object) read_attribute_for_validation(key)
Implements the ActiveModel::Validation hook method.
9 10 11 |
# File 'lib/neo4j/rails/validations.rb', line 9 def read_attribute_for_validation(key) respond_to?(key) ? send(key) : self[key] end |
- (Boolean) save(options = {})
The validation process on save can be skipped by passing false. The regular Model#save method is replaced with this when the validations module is mixed in, which it is by default.
18 19 20 21 22 23 24 |
# File 'lib/neo4j/rails/validations.rb', line 18 def save(={}) result = perform_validations() ? super : false if !result Neo4j::Rails::Transaction.fail if Neo4j::Rails::Transaction.running? end result end |
- (Boolean) valid?(context = nil)
True if valid
27 28 29 30 31 |
# File 'lib/neo4j/rails/validations.rb', line 27 def valid?(context = nil) context ||= (new_record? ? :create : :update) super(context) errors.empty? end |