Class: ActiveRecord::Update::Result
- Inherits:
-
Object
- Object
- ActiveRecord::Update::Result
- Defined in:
- lib/activerecord-update/active_record/update/result.rb
Overview
This class represents the result return by the Base#update_records method. It contains the ID’s of the records that were updated and the records that failed to validate and
Instance Attribute Summary collapse
-
#failed_records ⇒ <ActiveRecord::Base>
readonly
The records that failed to validate.
-
#ids ⇒ <Integer>
readonly
The ID’s of the records that were updated.
-
#stale_objects ⇒ <ActiveRecord::Base>
readonly
The records that failed to update due to being stale.
Instance Method Summary collapse
-
#failed_records? ⇒ Boolean
‘true` if there were records that failed to validate.
-
#initialize(ids, failed_records, stale_objects) ⇒ Result
constructor
Initialize the receiver.
-
#stale_objects? ⇒ Boolean
‘true` if there were any stale objects.
-
#success? ⇒ Boolean
‘true` if there were no failed records or stale objects.
-
#updates? ⇒ Boolean
‘true` if there were any updated records.
Constructor Details
#initialize(ids, failed_records, stale_objects) ⇒ Result
Initialize the receiver.
31 32 33 34 35 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 31 def initialize(ids, failed_records, stale_objects) @ids = ids @failed_records = failed_records @stale_objects = stale_objects end |
Instance Attribute Details
#failed_records ⇒ <ActiveRecord::Base> (readonly)
Returns the records that failed to validate.
13 14 15 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 13 def failed_records @failed_records end |
#ids ⇒ <Integer> (readonly)
Returns the ID’s of the records that were updated.
10 11 12 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 10 def ids @ids end |
#stale_objects ⇒ <ActiveRecord::Base> (readonly)
The records that failed to update due to being stale.
Can only contain objects if optimistic locking is used.
20 21 22 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 20 def stale_objects @stale_objects end |
Instance Method Details
#failed_records? ⇒ Boolean
Returns ‘true` if there were records that failed to validate.
44 45 46 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 44 def failed_records? failed_records.any? end |
#stale_objects? ⇒ Boolean
Returns ‘true` if there were any stale objects.
54 55 56 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 54 def stale_objects? stale_objects.any? end |
#success? ⇒ Boolean
Returns ‘true` if there were no failed records or stale objects.
39 40 41 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 39 def success? !failed_records? && !stale_objects? end |
#updates? ⇒ Boolean
Returns ‘true` if there were any updated records.
49 50 51 |
# File 'lib/activerecord-update/active_record/update/result.rb', line 49 def updates? ids.any? end |