class RuboCop::Cop::SketchupSuggestions::ToolInvalidate

After having drawn to the viewport from a tool, make sure to invalidate the view on `deactivate` and `suspend`.

If you don't do that the things you drew might stick around for longer than the life-span of the tool and cause confusion for the user.

@example

# good
class ExampleTool

  def deactivate(view)
    view_invalidate
  end

  def suspend(view)
    view_invalidate
  end

  def draw(view)
    view.draw(GL_LINES, @points)
  end

end

Constants

MSG_MISSING_INVALIDATE
MSG_MISSING_INVALIDATE_METHOD

Public Instance Methods

on_tool_class(class_node, body_methods) click to toggle source
# File lib/rubocop/sketchup/cop/suggestions/tool_invalidate.rb, line 43
def on_tool_class(class_node, body_methods)
  return unless find_method(body_methods, :draw)

  check_method_invalidate(:deactivate, body_methods, class_node)
  check_method_invalidate(:suspend, body_methods, class_node)
end

Private Instance Methods

check_method_invalidate(method_name, body_methods, class_node) click to toggle source
# File lib/rubocop/sketchup/cop/suggestions/tool_invalidate.rb, line 52
def check_method_invalidate(method_name, body_methods, class_node)
  method_node = find_method(body_methods, method_name)
  if method_node
    return if view_invalidate?(method_node)

    add_offense(method_node, message: MSG_MISSING_INVALIDATE)
  else
    add_offense(class_node, message: MSG_MISSING_INVALIDATE_METHOD)
  end
end