class Renamespace::RenameWithinFileContent

Attributes

can_omit_prefixes_count[R]
content_orig[R]
paths[R]
replacements_logger[R]

Public Class Methods

new(paths:, content:, can_omit_prefixes_count:, replacements_logger:) click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 7
def initialize(paths:, content:, can_omit_prefixes_count:, replacements_logger:)
  @paths = paths
  @content_orig = content
  @can_omit_prefixes_count = can_omit_prefixes_count
  @replacements_logger = replacements_logger
end

Public Instance Methods

call() click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 14
def call
  content_orig
    .then(&method(:replace_require_paths))
    .then(&method(:replace_references))
end
namespace_elements_dest() click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 50
def namespace_elements_dest
  @namespace_elements_dest ||= paths.destination_namespace_elements
end
namespace_elements_source() click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 46
def namespace_elements_source
  @namespace_elements_source ||= paths.source_namespace_elements
end
replace_references(content) click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 24
def replace_references(content)
  (1 + can_omit_prefixes_count).times do
    replacements_logger.log(search_str, replace_str)
    content = content.gsub(search_regex, replace_str)
    namespace_elements_source.shift
    namespace_elements_dest.shift
  end
  content
end
replace_require_paths(content) click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 20
def replace_require_paths(content)
  content.gsub(paths.source_require_path, paths.destination_require_path)
end
replace_str() click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 42
def replace_str
  namespace_elements_dest.join('::')
end
search_regex() click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 34
def search_regex
  /\b#{namespace_elements_source.join('::')}\b/
end
search_str() click to toggle source
# File lib/renamespace/rename_within_file_content.rb, line 38
def search_str
  namespace_elements_source.join('::')
end