Class: Archimate::Cli::Cleanup

Inherits:
Object
  • Object
show all
Defined in:
lib/archimate/cli/cleanup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, output, options) ⇒ Cleanup

Returns a new instance of Cleanup.



18
19
20
21
22
23
24
25
# File 'lib/archimate/cli/cleanup.rb', line 18

def initialize(model, output, options)
  @model = model
  @output = output
  @options = options
  @trash = Nokogiri::XML::Document.new("<deleted></deleted>")
  @model_set = nil
  @progressbar = ProgressIndicator.new(total: model.unreferenced_nodes.size, title: "Elements")
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



11
12
13
# File 'lib/archimate/cli/cleanup.rb', line 11

def model
  @model
end

Class Method Details

.cleanup(input, output, options) ⇒ Object



13
14
15
16
# File 'lib/archimate/cli/cleanup.rb', line 13

def self.cleanup(input, output, options)
  cleaner = new(Archimate.read(input), output, options)
  cleaner.clean
end

Instance Method Details

#cleanObject



43
44
45
46
47
48
49
50
# File 'lib/archimate/cli/cleanup.rb', line 43

def clean
  return unless model

  remove_unreferenced_nodes
  puts "Found #{unref_set.size} model items unreferenced by diagram or relationships"
  Archimate::ArchiFileWriter.write(model, output)
  write_trash
end

#remove_unreferenced_nodesObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/archimate/cli/cleanup.rb', line 27

def remove_unreferenced_nodes
  model.unreferenced_nodes.each do |unreferenced_node|
    raise "This functionality is not implemeted yet"

    # TODO: this needs to be the XML serialization of the node
    trash.root.add_child unreferenced_node.dup
    # TODO: implement this
    # model.delete(unreferenced_node)
    @progressbar.increment
  end
end

#write_trashObject



39
40
41
# File 'lib/archimate/cli/cleanup.rb', line 39

def write_trash
  options[:saveremoved].write(trash)
end