Module: Journaled::RelationChangeProtection
- Defined in:
- lib/journaled/relation_change_protection.rb
Instance Method Summary collapse
- #delete_all(force: false) ⇒ Object
-
#update_all(updates, opts = { force: false }) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#delete_all(force: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/journaled/relation_change_protection.rb', line 28 def delete_all(force: false) if force || !model.respond_to?(:journaled_attribute_names) || model.journaled_attribute_names.empty? super() else raise(" #delete_all aborted by Journaled::Changes.\n\n Call .destroy_all instead to ensure journaling or invoke .delete_all(force: true)\n to override and skip journaling.\n ERROR\n end\nend\n") |
#update_all(updates, opts = { force: false }) ⇒ Object
rubocop:disable Metrics/AbcSize
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/journaled/relation_change_protection.rb', line 4 def update_all(updates, opts = { force: false }) # rubocop:disable Metrics/AbcSize unless opts[:force] || !model.respond_to?(:journaled_attribute_names) || model.journaled_attribute_names.empty? conflicting_journaled_attribute_names = case updates when Hash model.journaled_attribute_names & updates.keys.map(&:to_sym) when String model.journaled_attribute_names.select do |a| updates.match?(/\b(?<!')#{a}(?!')\b/) end else raise "unsupported type '#{updates.class}' for 'updates'" end raise(" .update_all aborted by Journaled::Changes due to journaled attributes:\n\n \#{conflicting_journaled_attribute_names.join(', ')}\n\n Consider using .all(lock: true) or .find_each with #update to ensure journaling or invoke\n .update_all with additional arg `{ force: true }` to override and skip journaling.\n ERROR\n end\n super(updates)\nend\n") if conflicting_journaled_attribute_names.present? |