Class: ActiveRecordBetterDependentErrorMessages::DestroyValidator
- Inherits:
-
Object
- Object
- ActiveRecordBetterDependentErrorMessages::DestroyValidator
- Defined in:
- lib/active_record_better_dependent_error_messages/destroy_validator.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#root_model ⇒ Object
readonly
Returns the value of attribute root_model.
-
#trace ⇒ Object
readonly
Returns the value of attribute trace.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(root_model:, model:, trace:, args:) ⇒ DestroyValidator
constructor
A new instance of DestroyValidator.
Constructor Details
#initialize(root_model:, model:, trace:, args:) ⇒ DestroyValidator
Returns a new instance of DestroyValidator.
4 5 6 7 8 9 |
# File 'lib/active_record_better_dependent_error_messages/destroy_validator.rb', line 4 def initialize(root_model:, model:, trace:, args:) @args = args @root_model = root_model @model = model @trace = trace end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
2 3 4 |
# File 'lib/active_record_better_dependent_error_messages/destroy_validator.rb', line 2 def args @args end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
2 3 4 |
# File 'lib/active_record_better_dependent_error_messages/destroy_validator.rb', line 2 def model @model end |
#root_model ⇒ Object (readonly)
Returns the value of attribute root_model.
2 3 4 |
# File 'lib/active_record_better_dependent_error_messages/destroy_validator.rb', line 2 def root_model @root_model end |
#trace ⇒ Object (readonly)
Returns the value of attribute trace.
2 3 4 |
# File 'lib/active_record_better_dependent_error_messages/destroy_validator.rb', line 2 def trace @trace end |
Class Method Details
.call(root_model: nil, model:, trace: nil, **args) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/active_record_better_dependent_error_messages/destroy_validator.rb', line 11 def self.call(root_model: nil, model:, trace: nil, **args) root_model ||= model trace ||= [model] ActiveRecordBetterDependentErrorMessages::DestroyValidator.new(root_model: root_model, model: model, trace: trace, args: args).() end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/active_record_better_dependent_error_messages/destroy_validator.rb', line 18 def call model.class.reflect_on_all_associations.each do |association| if association.[:dependent] == :restrict_with_error || association.[:dependent] == :restrict_with_exception check_restrict_association(association) elsif association.[:dependent] == :destroy check_sub_destroy_association(association) end end end |