Class: Dependabot::Bundler::FileUpdater::GemspecSanitizer::Rewriter

Inherits:
Parser::TreeRewriter
  • Object
show all
Defined in:
lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(replacement_version:) ⇒ Rewriter

Returns a new instance of Rewriter.



49
50
51
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 49

def initialize(replacement_version:)
  @replacement_version = replacement_version
end

Instance Method Details

#on_send(node) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 53

def on_send(node)
  # Wrap any `require` or `require_relative` calls in a rescue
  # block, as we might not have the required files
  wrap_require(node) if requires_file?(node)

  # Remove any assignments to a VERSION constant (or similar), as
  # that constant probably comes from a required file
  replace_version_assignments(node)

  # Replace the `s.files= ...` assignment with a blank array, as
  # occasionally a File.open(..).readlines pattern is used
  replace_file_assignments(node)

  # Replace the `s.require_path= ...` assignment, as
  # occasionally a Dir['lib'] pattern is used
  replace_require_paths_assignments(node)

  # Replace any `File.read(...)` calls with a dummy string
  replace_file_reads(node)

  # Replace any `JSON.parse(...)` calls with a dummy hash
  replace_json_parses(node)

  # Remove the arguments from any `Find.find(...)` calls
  remove_find_dot_find_args(node)

  remove_unnecessary_assignments(node)
end