Class: StimulusGridRails::Audit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- StimulusGridRails::Audit
- Defined in:
- app/models/stimulus_grid_rails/audit.rb
Overview
One undoable cell mutation (RAILS.md ยง16). Recorded per successful cell commit; undo/redo replay the inverse/forward value as a normal mutation so validations re-run, cascades cascade, and broadcasts fire. Scoped per user + resource (not global).
Install the table with the migration shipped in the gem (or copy it):
rails stimulus_grid_rails:install:migrations && rails db:migrate
Class Method Summary collapse
-
.available? ⇒ Boolean
True once the table is installed.
-
.redoable(resource, user_id) ⇒ Object
Most-recently-undone mutation, ready to redo.
-
.undoable(resource, user_id) ⇒ Object
Most-recent not-yet-undone mutation for this user + resource.
Class Method Details
.available? ⇒ Boolean
True once the table is installed. Auditing (and undo/redo) is a no-op until then, so the rest of the gem works without the migration.
14 15 16 17 18 |
# File 'app/models/stimulus_grid_rails/audit.rb', line 14 def self.available? table_exists? rescue ActiveRecord::ActiveRecordError false end |
.redoable(resource, user_id) ⇒ Object
Most-recently-undone mutation, ready to redo.
27 28 29 30 |
# File 'app/models/stimulus_grid_rails/audit.rb', line 27 def self.redoable(resource, user_id) where(resource: resource.to_s, user_id: user_id, undone: true) .order(undone_at: :desc, id: :desc) end |
.undoable(resource, user_id) ⇒ Object
Most-recent not-yet-undone mutation for this user + resource.
21 22 23 24 |
# File 'app/models/stimulus_grid_rails/audit.rb', line 21 def self.undoable(resource, user_id) where(resource: resource.to_s, user_id: user_id, undone: false) .order(created_at: :desc, id: :desc) end |