2016-12-21 14:01:06 -07:00
|
|
|
module Tools
|
|
|
|
class Destroy < Mutations::Command
|
2017-03-08 07:20:11 -07:00
|
|
|
STILL_IN_USE = "Can't delete tool because the following sequences are "\
|
|
|
|
"still using it: %s"
|
|
|
|
STILL_IN_SLOT = "Can't delete tool because it is still in a tool slot. "\
|
2017-03-08 14:10:31 -07:00
|
|
|
"Please remove it from the tool slot first."
|
2017-03-08 07:20:11 -07:00
|
|
|
|
2016-12-21 14:01:06 -07:00
|
|
|
required do
|
|
|
|
model :tool, class: Tool
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate
|
2017-03-08 07:20:11 -07:00
|
|
|
any_deps?
|
|
|
|
any_slots?
|
2016-12-21 14:01:06 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
tool.destroy!
|
|
|
|
end
|
2017-03-08 07:20:11 -07:00
|
|
|
|
|
|
|
def any_slots?
|
|
|
|
add_error :tool, :in_slot, STILL_IN_SLOT if ToolSlot.where(tool: tool).any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def any_deps?
|
2018-02-11 12:59:54 -07:00
|
|
|
raise "REWRITE REQUIRED"
|
|
|
|
# names = SequenceDependency
|
|
|
|
# .includes(:sequence)
|
|
|
|
# .where(dependency: tool)
|
|
|
|
# .pluck("sequences.name")
|
|
|
|
# .map{|x| x || "Untitled sequence"}
|
|
|
|
# .join(", ")
|
|
|
|
# add_error :tool, :in_use, STILL_IN_USE % [names] if names.present?
|
2017-03-08 07:20:11 -07:00
|
|
|
end
|
2016-12-21 14:01:06 -07:00
|
|
|
end
|
|
|
|
end
|