Class: Koboldy::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/koboldy/run.rb

Instance Method Summary collapse

Constructor Details

#initialize(kobold_cmd = "kobold") ⇒ Run

Returns a new instance of Run.



7
8
9
# File 'lib/koboldy/run.rb', line 7

def initialize(kobold_cmd = "kobold")
  @cmd = kobold_cmd
end

Instance Method Details

#additional_option(command) ⇒ Self

Parameters:

  • command (String)

    Add aditional options.

Returns:

  • (Self)


59
60
61
62
# File 'lib/koboldy/run.rb', line 59

def additional_option(command)
  @cmd.concat(%( #{command}))
  self
end

#approved(expected_folder) ⇒ Self

Parameters:

  • expected_folder (String)

    A path to expected files

Returns:

  • (Self)


24
25
26
27
# File 'lib/koboldy/run.rb', line 24

def approved(expected_folder)
  @cmd.concat(%( --approved-folder "#{expected_folder}"))
  self
end

#base_uri(path) ⇒ Object

Parameters:

  • path (String)

    Path of current path.



65
66
67
# File 'lib/koboldy/run.rb', line 65

def base_uri(path)
  @cmd.concat(%( "#{path}"))
end

#build(test_target_folder) ⇒ Self

Parameters:

  • test_target_folder (String)

    A path to test target files

Returns:

  • (Self)


38
39
40
41
# File 'lib/koboldy/run.rb', line 38

def build(test_target_folder)
  @cmd.concat(%( --build-folder "#{test_target_folder}"))
  self
end

#check_and_save(in_file_path = %(./tmp/kobold.txt)) ⇒ String

Returns File path which is saved results.

Parameters:

  • in_file_path (String) (defaults to: %(./tmp/kobold.txt))

    A path to file which you would like to save standard output and error.

Returns:

  • (String)

    File path which is saved results.



71
72
73
74
75
76
# File 'lib/koboldy/run.rb', line 71

def check_and_save(in_file_path = %(./tmp/kobold.txt))
  fail "no command: #{@cmd}" if @cmd.nil?
  FileUtils.mkdir_p(File::dirname(in_file_path)) unless Dir.exist?(File::dirname(in_file_path))
  Koboldy::Io.capture(@cmd, in_file_path)
  in_file_path
end

#clear_cmd(kobold_cmd = "kobold") ⇒ Object



11
12
13
# File 'lib/koboldy/run.rb', line 11

def clear_cmd(kobold_cmd = "kobold")
  @cmd = kobold_cmd
end

#config(file) ⇒ Self

Parameters:

  • file (String)

    A path to configuration file

Returns:

  • (Self)


17
18
19
20
# File 'lib/koboldy/run.rb', line 17

def config(file)
  @cmd.concat(%( --config "#{file}"))
  self
end

#fail_additionsSelf

Add “–fail-additions” option

Returns:

  • (Self)


52
53
54
55
# File 'lib/koboldy/run.rb', line 52

def fail_additions
  @cmd.concat(%( --fail-additions))
  self
end

#fail_orphansSelf

Add “–fail-orphans” option

Returns:

  • (Self)


45
46
47
48
# File 'lib/koboldy/run.rb', line 45

def fail_orphans
  @cmd.concat(%( --fail-orphans))
  self
end

#highlight(compared_folder) ⇒ Self

Parameters:

  • compared_folder (String)

    A path to compared files

Returns:

  • (Self)


31
32
33
34
# File 'lib/koboldy/run.rb', line 31

def highlight(compared_folder)
  @cmd.concat(%( --highlight-folder "#{compared_folder}"))
  self
end

#results(from_path, into_file = "") ⇒ String

Returns into_file A path to saved result file.

Parameters:

  • from_path (String)

    A path you would like to analysis outputs by kobold command.

  • into_file(Option) (String)

    A path you would like to save the result. If into_file is empty, then the method return JSON.

Returns:

  • (String)

    into_file A path to saved result file.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/koboldy/run.rb', line 81

def results(from_path, into_file = "")
  fail ArgumentError, "no #{from_path}" unless File.exist? from_path
  result = File.read(from_path)
  add, orp, dif = additions(result), orphans(result), different(result)

  hash = {
    :passing => passing(result),
    :failing =>  failing(result),
    :pending => pending(result),
    :additions => { count: add.length, messages: add }, # 期待結果に無い
    :orphans => { count: orp.length, messages: orp }, # 比較対象に無い
    :different => { count: dif.length, messages: dif }, # 比較結果が異なる
  }

  return JSON.pretty_generate(hash) if into_file.empty?

  File.write(into_file, JSON.pretty_generate(hash))
  into_file
end