Class: Mxrb::Semantic::Renamer
- Inherits:
-
Object
- Object
- Mxrb::Semantic::Renamer
- Defined in:
- lib/mxrb/semantic/renamer.rb
Overview
Plans and applies model-wide renames without introducing a query language. Every changed BSON string is visible in the Ruby preview.
Constant Summary collapse
- METADATA_FIELDS =
%w[Documentation documentation Caption caption Text text].freeze
Instance Method Summary collapse
-
#initialize(project) ⇒ Renamer
constructor
A new instance of Renamer.
- #plan(source_name, to:, cross_module: false) ⇒ Object
Constructor Details
#initialize(project) ⇒ Renamer
Returns a new instance of Renamer.
44 45 46 |
# File 'lib/mxrb/semantic/renamer.rb', line 44 def initialize(project) @project = project end |
Instance Method Details
#plan(source_name, to:, cross_module: false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mxrb/semantic/renamer.rb', line 48 def plan(source_name, to:, cross_module: false) source = resolve(source_name) target = qualified_target(source, to, cross_module: cross_module) reject_collision(source, target) changes = [] documents = {} @project.all_units.each do |raw| original = @project.parse_bson(raw) transformed = transform( original, source:, target:, unit_id: raw.fetch("UnitID"), target_unit: source.unit_id == raw.fetch("UnitID"), changes: ) documents[raw.fetch("UnitID")] = transformed unless transformed.equal?(original) end original_architecture = @project.architecture_definition architecture = if original_architecture transform( original_architecture, source:, target:, unit_id: "architecture", target_unit: false, changes: ) end RenamePlan.new( project: @project, source:, target:, changes:, documents:, architecture: ) end |