Module: Crabfarm::Modes::Shared::SnapshotDecorator

Defined in:
lib/crabfarm/modes/shared/snapshot_decorator.rb

Defined Under Namespace

Modules: Colors

Class Method Summary collapse

Class Method Details

.decorate(_navigator) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/crabfarm/modes/shared/snapshot_decorator.rb', line 13

def self.decorate(_navigator)

  def _navigator.execute_reducer(_reducer)
    loop do
      name = Ask.input "-- Name for #{_reducer.class.to_s} snapshot (blank to skip)".color Colors::QUESTION
      if name.empty?
        puts "-- Skipping snapshot".color Colors::WARNING
        break
      else
        file_path = _reducer.class.snapshot_path name

        if File.exist? file_path
          puts "-- Could not save snapshot, file already exist!".color Colors::ERROR
        else
          dir_path = file_path.split(File::SEPARATOR)[0...-1]
          FileUtils.mkpath dir_path.join(File::SEPARATOR) if dir_path.length > 0
          File.write file_path, _reducer.raw_document
          puts "-- Snapshot written to #{file_path}".color Colors::RESULT
          break
        end
      end
    end

    _reducer.run
  end

  _navigator
end