Farmbot-Web-App/app/mutations/tools/destroy.rb

37 lines
968 B
Ruby
Raw Normal View History

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. "\
"Please remove it from the tool slot first."
2017-03-08 07:20:11 -07:00
required do
model :tool, class: Tool
end
def validate
2017-03-08 07:20:11 -07:00
any_deps?
any_slots?
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?
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
end
end