Class: Liri::Common::SourceCode

Inherits:
Object
  • Object
show all
Defined in:
lib/common/source_code.rb

Constant Summary collapse

DECOMPRESSED_FOLDER_NAME =
'decompressed'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_path, compressed_file_folder_path, ignored_folders, compression_class, unit_test_class) ⇒ SourceCode

Returns a new instance of SourceCode.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/common/source_code.rb', line 11

def initialize(folder_path, compressed_file_folder_path, ignored_folders, compression_class, unit_test_class)
  @folder_path = folder_path
  @folder_name = @folder_path.split('/').last
  @compressed_file_folder_path = compressed_file_folder_path
  @decompressed_file_folder_path = File.join(@compressed_file_folder_path, '/', DECOMPRESSED_FOLDER_NAME)
  @compressed_file_path = File.join(@compressed_file_folder_path, '/', "#{@folder_name}.zip")
  # Inicializa un compresor acorde a compression_class, la siguiente línea en realidad hace lo siguiente:
  # @compressor = Liri::Common::Compressor::Zip.new(input_dir, output_file)
  # compression_class en este caso es Zip pero podría ser otro si existiera la implementación, por ejemplo Rar
  @compressor = Object.const_get(compression_class).new(@folder_path, @compressed_file_path, ignored_folders)
  # Inicializa un ejecutor de pruebas acorde a unit_test_class, la siguiente línea en realidad hace lo siguiente:
  # @unit_test = Liri::Common::UnitTest::Rspec.new(source_code_folder_path)
  # unit_test_class en este caso es Rspec pero podría ser otro si existiera la implementación, por ejemplo UnitTest
  @unit_test = Object.const_get(unit_test_class).new(@folder_path)
end

Instance Attribute Details

#compressed_file_folder_pathObject (readonly)

Returns the value of attribute compressed_file_folder_path.



9
10
11
# File 'lib/common/source_code.rb', line 9

def compressed_file_folder_path
  @compressed_file_folder_path
end

#compressed_file_pathObject (readonly)

Returns the value of attribute compressed_file_path.



9
10
11
# File 'lib/common/source_code.rb', line 9

def compressed_file_path
  @compressed_file_path
end

#decompressed_file_folder_pathObject (readonly)

Returns the value of attribute decompressed_file_folder_path.



9
10
11
# File 'lib/common/source_code.rb', line 9

def decompressed_file_folder_path
  @decompressed_file_folder_path
end

#folder_pathObject (readonly)

Returns the value of attribute folder_path.



9
10
11
# File 'lib/common/source_code.rb', line 9

def folder_path
  @folder_path
end

Instance Method Details

#all_testsObject



58
59
60
# File 'lib/common/source_code.rb', line 58

def all_tests
  @unit_test.all_tests
end

#compress_folderObject



27
28
29
# File 'lib/common/source_code.rb', line 27

def compress_folder
  @compressor.compress
end

#decompress_file(compressed_file_path = @compressed_file_path) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/common/source_code.rb', line 31

def decompress_file(compressed_file_path = @compressed_file_path)
  if File.exist?(compressed_file_path)
    @compressor.decompress(compressed_file_path, @decompressed_file_folder_path)
    Dir.exist?(@decompressed_file_folder_path) ? true : false
  else
    raise FileNotFoundError, compressed_file_path
  end
end

#delete_compressed_fileObject



40
41
42
43
44
45
46
47
# File 'lib/common/source_code.rb', line 40

def delete_compressed_file
  if File.exist?(@compressed_file_path)
    File.delete(@compressed_file_path)
    true
  else
    false
  end
end

#delete_decompressed_file_folder_pathObject



49
50
51
52
53
54
55
56
# File 'lib/common/source_code.rb', line 49

def delete_decompressed_file_folder_path
  if Dir.exist?(@decompressed_file_folder_path)
    FileUtils.rm_rf(@decompressed_file_folder_path)
    Dir.exist?(@decompressed_file_folder_path) ? false : true
  else
    false
  end
end