Files
fizzy/app/models/command.rb
T
Jorge Manrubia 50b4f34f34 Copy tweaks
2025-07-01 09:51:11 +02:00

72 lines
1.3 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
def error_messages
errors.to_hash.flat_map do |attribute, message|
error_message_for(attribute, message)
end.uniq
end
private
def redirect_to(...)
Command::Result::Redirection.new(...)
end
def error_message_for(attribute, message)
case attribute.to_sym
when :cards, :card_ids
"Needs one or more cards to apply to (#123, #124)"
when :card
"Needs one card to apply to."
when :collection
"You need to specify a Collection"
when :assignee_ids
"Needs at least one assignee (@person)."
when :user
"Cant find that person."
when :stage
"Cant find that Workflow Stage."
when :tag_title
"Needs at least one tag (#tag, #name)"
else
message
end
end
end