Module: Iry
- Defined in:
- lib/iry.rb,
lib/iry/patch.rb,
lib/iry/macros.rb,
lib/iry/version.rb,
lib/iry/handlers.rb,
lib/iry/callbacks.rb,
lib/iry/constraint.rb,
lib/iry/handlers/pg.rb,
lib/iry/handlers/null.rb,
lib/iry/constraint/check.rb,
lib/iry/constraint/unique.rb,
lib/iry/constraint/exclusion.rb,
lib/iry/transform_constraints.rb,
lib/iry/constraint/foreign_key.rb
Overview
Entrypoint of constraint validation, include in a class inheriting ActiveRecord::Base and the following class-level methods will be available:
Defined Under Namespace
Modules: Constraint, Error, Handlers, Macros, Patch, TransformConstraints Classes: ConstraintViolation, StatementInvalid
Constant Summary collapse
- VERSION =
File.read(File.("../../VERSION", __dir__)).strip.freeze
Class Method Summary collapse
-
.destroy(model) ⇒ Handlers::Model
Similar to ActiveRecord::Base#destroy but in case of constraint violations, ‘false` is returned and `errors` are populated.
-
.handle_constraints(model) { ... } ⇒ nil, Handlers::Model
Executes block and in case of constraints violations on ‘model`, block is halted and errors are appended to `model`.
-
.handle_constraints!(model) { ... } ⇒ Handlers::Model
Executes block and in case of constraints violations on ‘model`, block is halted, errors are appended to `model` and StatementInvalid is raised.
-
.save(model) ⇒ Boolean
Similar to ActiveRecord::Base#save but in case of constraint violations, ‘false` is returned and `errors` are populated.
-
.save!(model) ⇒ true
Similar to ActiveRecord::Base#save! but in case of constraint violations, it raises ConstraintViolation and ‘errors` are populated.
Instance Method Summary collapse
-
#record ⇒ Handlers::Model
Inherited from ActiveRecord::RecordInvalid, returns the model for which the constraint violations have been detected.
Class Method Details
.destroy(model) ⇒ Handlers::Model
Similar to ActiveRecord::Base#destroy but in case of constraint violations, ‘false` is returned and `errors` are populated.
153 154 155 |
# File 'lib/iry.rb', line 153 def self.destroy(model) TransformConstraints.destroy(model) end |
.handle_constraints(model) { ... } ⇒ nil, Handlers::Model
Executes block and in case of constraints violations on ‘model`, block is halted and errors are appended to `model`
110 111 112 |
# File 'lib/iry.rb', line 110 def self.handle_constraints(model, &block) TransformConstraints.handle_constraints(model, &block) end |
.handle_constraints!(model) { ... } ⇒ Handlers::Model
Executes block and in case of constraints violations on ‘model`, block is halted, errors are appended to `model` and StatementInvalid is raised
120 121 122 |
# File 'lib/iry.rb', line 120 def self.handle_constraints!(model, &block) TransformConstraints.handle_constraints!(model, &block) end |
.save(model) ⇒ Boolean
Similar to ActiveRecord::Base#save but in case of constraint violations, ‘false` is returned and `errors` are populated. Aside from `model`, it takes the same arguments as ActiveRecord::Base#save
130 131 132 |
# File 'lib/iry.rb', line 130 def self.save(model, ...) TransformConstraints.save(model, ...) end |
.save!(model) ⇒ true
Similar to ActiveRecord::Base#save! but in case of constraint violations, it raises ConstraintViolation and ‘errors` are populated. Aside from `model`, it takes the same arguments as ActiveRecord::Base#save!
145 146 147 |
# File 'lib/iry.rb', line 145 def self.save!(model, ...) TransformConstraints.save!(model, ...) end |
Instance Method Details
#record ⇒ Handlers::Model
Inherited from ActiveRecord::RecordInvalid, returns the model for which the constraint violations have been detected
|
# File 'lib/iry.rb', line 50
|