Class: RuboCop::Cop::SketchupRequirements::SketchupRequire

Inherits:
SketchUp::Cop
  • Object
show all
Includes:
RangeHelp, SketchUp::ExtensionProject, SketchUp::NoCommentDisable
Defined in:
lib/rubocop/sketchup/cop/requirements/sketchup_require.rb

Overview

Omit file extensions when using ‘Sketchup.require` to allow encrypted files to be loaded.

Ruby C extensions, ‘.so`/`.bundle` libraries must always be loaded via the normal `require`.

Examples:

Bad - This will fail if extension is encrypted

Sketchup.require 'hello/world.rb'

Good - This will work for ‘.rbe`, `.rbs` and `rb` files.

Sketchup.require 'hello/world'

Bad - This will fail if extension is encrypted

extension = SketchupExtension.new("Example", "Example/main.rb")

Good - This will work for ‘.rbe`, `.rbs` and `rb` files.

extension = SketchupExtension.new("Example", "Example/main")

Constant Summary collapse

MSG_SKETCHUP_REQUIRE_EXT_NAME =
'Do not hard code file extensions '\
'with `Sketchup.require`.'
MSG_EXTENSION_NEW_EXT_NAME =
'Do not hard code file extensions '\
'with `SketchupExtension.new`.'
MSG_REQUIRE_FOR_BINARY =
'Use `require` instead of `Sketchup.require` '\
'to load binary Ruby libraries.'
MSG_REQUIRE_ENCRYPTED =
'Use `Sketchup.require` when loading Ruby '\
'files for encrypted extensions.'
TOOLS_RUBY_FILES =
%w[extensions.rb langhandler.rb sketchup.rb].freeze

Constants included from SketchUp::Config

SketchUp::Config::DEFAULT_CONFIGURATION

Constants inherited from SketchUp::Cop

SketchUp::Cop::SKETCHUP_DEPARTMENT_SEVERITY

Instance Method Summary collapse

Methods included from SketchUp::ExtensionProject

#config_path, #extension_directory, #extension_root_file, #extension_root_files, #path_relative_to_source, #relative_source_path, #root_file?, #source_path

Methods inherited from SketchUp::Cop

inherited, #relevant_file?

Instance Method Details

#on_send(node) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rubocop/sketchup/cop/requirements/sketchup_require.rb', line 71

def on_send(node)
  if sketchup_require?(node)
    filename = sketchup_require(node)
    return if check_binary_sketchup_require(node, filename)
    return if check_sketchup_require_filename(node, filename)

  elsif ruby_require?(node)
    filename = ruby_require(node)
    return if check_encrypted_require(node, filename)

  elsif sketchup_extension_new?(node)
    filename = sketchup_extension_new(node)
    return if check_sketchup_extension_new_filename(node, filename)

  end
end