2510c1e0ac
- Big simplification of the overall workflow. - Composite commands store their commands properly, these are undoable now. - Child commands are excluded from history
45 lines
588 B
Ruby
45 lines
588 B
Ruby
class Command < ApplicationRecord
|
|
include Rails.application.routes.url_helpers
|
|
|
|
belongs_to :user
|
|
belongs_to :parent, class_name: "Command", optional: true
|
|
|
|
scope :root, ->{ where(parent_id: nil) }
|
|
|
|
attribute :context
|
|
|
|
def title
|
|
model_name.human
|
|
end
|
|
|
|
def confirmation_prompt
|
|
title
|
|
end
|
|
|
|
def execute
|
|
end
|
|
|
|
def undo
|
|
end
|
|
|
|
def undo!
|
|
transaction do
|
|
undo
|
|
destroy
|
|
end
|
|
end
|
|
|
|
def undoable?
|
|
false
|
|
end
|
|
|
|
def needs_confirmation?
|
|
false
|
|
end
|
|
|
|
private
|
|
def redirect_to(...)
|
|
Command::Result::Redirection.new(...)
|
|
end
|
|
end
|