Class: Mxrb::Semantic::ExtractionPlan

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

Overview

Plan produced by Extractor#plan. Describes what will be extracted and applies the change atomically when apply! is called.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, source:, new_name:, selected_ids:, inner_objects:, inner_flows:, entry_flow:, exit_flow:, source_doc:, source_raw:) ⇒ ExtractionPlan

Returns a new instance of ExtractionPlan.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mxrb/semantic/extractor.rb', line 13

def initialize(project:, source:, new_name:, selected_ids:,
               inner_objects:, inner_flows:,
               entry_flow:, exit_flow:,
               source_doc:, source_raw:)
  @project = project
  @source = source
  @new_name = new_name
  @selected_ids = selected_ids
  @inner_objects = inner_objects
  @inner_flows = inner_flows
  @entry_flow = entry_flow
  @exit_flow = exit_flow
  @source_doc = source_doc
  @source_raw = source_raw
  @applied = false
end

Instance Attribute Details

#new_nameObject (readonly)

Returns the value of attribute new_name.



11
12
13
# File 'lib/mxrb/semantic/extractor.rb', line 11

def new_name
  @new_name
end

#selected_idsObject (readonly)

Returns the value of attribute selected_ids.



11
12
13
# File 'lib/mxrb/semantic/extractor.rb', line 11

def selected_ids
  @selected_ids
end

#sourceObject (readonly)

Returns the value of attribute source.



11
12
13
# File 'lib/mxrb/semantic/extractor.rb', line 11

def source
  @source
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


30
# File 'lib/mxrb/semantic/extractor.rb', line 30

def applied? = @applied

#apply!Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mxrb/semantic/extractor.rb', line 40

def apply!
  raise ArgumentError, "extraction plan was already applied" if applied?

  module_unit_id = find_module_unit_id
  @project.mpr.transaction do
    insert_extracted_microflow!(module_unit_id)
    patch_source_microflow!
  end
  @project.refresh!
  @applied = true
  self
end

#changesObject



32
33
34
35
36
37
38
# File 'lib/mxrb/semantic/extractor.rb', line 32

def changes
  [
    "extract #{@inner_objects.size} activit#{@inner_objects.size == 1 ? 'y' : 'ies'} " \
      "from #{@source.qualified_name} into #{@new_name}",
    "replace selection in #{@source.qualified_name} with call to #{@new_name}"
  ]
end