Class: ActiveRecord::Update::Result

Inherits:
Object
  • Object
show all
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

See Also:

  • Base#update_records

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ids, failed_records, stale_objects) ⇒ Result

Initialize the receiver.

Parameters:

  • ids (<Integer>)

    the ID’s of the records that were updated.

  • failed_records (<ActiveRecord::Base>)

    the records that failed to validate

  • stale_objects (<ActiveRecord::Base>)

    the records that failed to update to due being stale



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.

Returns:



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.

Returns:

  • (<Integer>)

    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.

Returns:



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.

Returns:

  • (Boolean)

    ‘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.

Returns:

  • (Boolean)

    ‘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.

Returns:

  • (Boolean)

    ‘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.

Returns:

  • (Boolean)

    ‘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