Class: Mxrb::Semantic::RenamePlan

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/semantic/renamer.rb

Overview

Immutable preview plus the prepared BSON documents needed for an explicit apply. Construct plans through Project#plan_rename.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, source:, target:, changes:, documents:, architecture: nil) ⇒ RenamePlan

Returns a new instance of RenamePlan.



12
13
14
15
16
17
18
19
20
# File 'lib/mxrb/semantic/renamer.rb', line 12

def initialize(project:, source:, target:, changes:, documents:, architecture: nil)
  @project = project
  @source = source
  @target = target
  @changes = changes.freeze
  @documents = documents.freeze
  @architecture = architecture
  @applied = false
end

Instance Attribute Details

#architectureObject (readonly)

Returns the value of attribute architecture.



10
11
12
# File 'lib/mxrb/semantic/renamer.rb', line 10

def architecture
  @architecture
end

#changesObject (readonly)

Returns the value of attribute changes.



10
11
12
# File 'lib/mxrb/semantic/renamer.rb', line 10

def changes
  @changes
end

#documentsObject (readonly)

Returns the value of attribute documents.



10
11
12
# File 'lib/mxrb/semantic/renamer.rb', line 10

def documents
  @documents
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/mxrb/semantic/renamer.rb', line 10

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/mxrb/semantic/renamer.rb', line 10

def target
  @target
end

Instance Method Details

#affected_unitsObject



24
# File 'lib/mxrb/semantic/renamer.rb', line 24

def affected_units = @documents.keys.freeze

#applied?Boolean

Returns:

  • (Boolean)


23
# File 'lib/mxrb/semantic/renamer.rb', line 23

def applied? = @applied

#apply!Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mxrb/semantic/renamer.rb', line 26

def apply!
  raise ArgumentError, "rename plan was already applied" if @applied

  @project.mpr.transaction do
    @documents.each { |unit_id, document| @project.mpr.update_unit(unit_id, document) }
    @project.mpr.write_architecture_definition(@architecture) if @architecture
  end
  @project.refresh!
  @applied = true
  self
end

#empty?Boolean

Returns:

  • (Boolean)


22
# File 'lib/mxrb/semantic/renamer.rb', line 22

def empty? = @changes.empty?