Class: Liri::Common::Setup
- Inherits:
-
Object
- Object
- Liri::Common::Setup
- Defined in:
- lib/common/setup.rb
Constant Summary collapse
- SETUP_FOLDER_NAME =
'liri'
- SETUP_FILE_NAME =
'liri-config.yml'
- TEMPLATE_PATH =
File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'template/liri-config.yml')
- LOGS_FOLDER_NAME =
'logs'
- MANAGER_FOLDER_NAME =
'manager'
- AGENT_FOLDER_NAME =
'agent'
Instance Attribute Summary collapse
-
#agent_folder_path ⇒ Object
readonly
Returns the value of attribute agent_folder_path.
-
#logs_folder_path ⇒ Object
readonly
Returns the value of attribute logs_folder_path.
-
#manager_folder_path ⇒ Object
readonly
Returns the value of attribute manager_folder_path.
-
#manager_tests_results_folder_path ⇒ Object
readonly
Returns the value of attribute manager_tests_results_folder_path.
-
#setup_file_path ⇒ Object
readonly
Returns the value of attribute setup_file_path.
-
#setup_folder_path ⇒ Object
readonly
Returns the value of attribute setup_folder_path.
Instance Method Summary collapse
- #create_folder(folder_path) ⇒ Object
-
#create_setup_file ⇒ Object
Crea un archivo de configuración en la raiz del proyecto desde un template.
-
#delete_setup_file ⇒ Object
Borra el archivo de configuración.
- #delete_setup_folder ⇒ Object
- #init ⇒ Object
-
#initialize(destination_folder_path, program, manager_tests_results_folder_time: nil) ⇒ Setup
constructor
A new instance of Setup.
-
#load ⇒ Object
Retorna los datos del archivo de configuración.
- #set(value, *keys) ⇒ Object
Constructor Details
#initialize(destination_folder_path, program, manager_tests_results_folder_time: nil) ⇒ Setup
Returns a new instance of Setup.
20 21 22 23 24 25 26 27 28 |
# File 'lib/common/setup.rb', line 20 def initialize(destination_folder_path, program, manager_tests_results_folder_time: nil) @setup_folder_path = File.join(destination_folder_path, '/', SETUP_FOLDER_NAME) @setup_file_path = File.join(@setup_folder_path, '/', SETUP_FILE_NAME) @logs_folder_path = File.join(@setup_folder_path, '/', LOGS_FOLDER_NAME) @manager_folder_path = File.join(@setup_folder_path, '/', MANAGER_FOLDER_NAME) @manager_tests_results_folder_path = File.join(@manager_folder_path, '/', "#{manager_tests_results_folder_time}_tests_results") if manager_tests_results_folder_time @agent_folder_path = File.join(@setup_folder_path, '/', AGENT_FOLDER_NAME) @program = program end |
Instance Attribute Details
#agent_folder_path ⇒ Object (readonly)
Returns the value of attribute agent_folder_path.
17 18 19 |
# File 'lib/common/setup.rb', line 17 def agent_folder_path @agent_folder_path end |
#logs_folder_path ⇒ Object (readonly)
Returns the value of attribute logs_folder_path.
17 18 19 |
# File 'lib/common/setup.rb', line 17 def logs_folder_path @logs_folder_path end |
#manager_folder_path ⇒ Object (readonly)
Returns the value of attribute manager_folder_path.
17 18 19 |
# File 'lib/common/setup.rb', line 17 def manager_folder_path @manager_folder_path end |
#manager_tests_results_folder_path ⇒ Object (readonly)
Returns the value of attribute manager_tests_results_folder_path.
17 18 19 |
# File 'lib/common/setup.rb', line 17 def manager_tests_results_folder_path @manager_tests_results_folder_path end |
#setup_file_path ⇒ Object (readonly)
Returns the value of attribute setup_file_path.
17 18 19 |
# File 'lib/common/setup.rb', line 17 def setup_file_path @setup_file_path end |
#setup_folder_path ⇒ Object (readonly)
Returns the value of attribute setup_folder_path.
17 18 19 |
# File 'lib/common/setup.rb', line 17 def setup_folder_path @setup_folder_path end |
Instance Method Details
#create_folder(folder_path) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/common/setup.rb', line 69 def create_folder(folder_path) if Dir.exist?(folder_path) false else Dir.mkdir(folder_path) Dir.exist?(folder_path) ? true : false end end |
#create_setup_file ⇒ Object
Crea un archivo de configuración en la raiz del proyecto desde un template
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/common/setup.rb', line 88 def create_setup_file if File.exist?(@setup_file_path) false else File.open(@setup_file_path, 'w') do |output_file| File.foreach(TEMPLATE_PATH) do |input_line| output_file.write(input_line) end end File.exist?(@setup_file_path) ? true : false end end |
#delete_setup_file ⇒ Object
Borra el archivo de configuración
103 104 105 106 107 108 109 110 |
# File 'lib/common/setup.rb', line 103 def delete_setup_file if File.exist?(@setup_file_path) File.delete(@setup_file_path) File.exist?(@setup_file_path) ? false : true else false end end |
#delete_setup_folder ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/common/setup.rb', line 78 def delete_setup_folder if Dir.exist?(@setup_folder_path) FileUtils.rm_rf(@setup_folder_path) Dir.exist?(@setup_folder_path) ? false : true else false end end |
#init ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/common/setup.rb', line 30 def init create_folder(@setup_folder_path) create_folder(@logs_folder_path) case @program when :manager create_folder(@manager_folder_path) create_folder(@manager_tests_results_folder_path) if @manager_tests_results_folder_path when :agent create_folder(@agent_folder_path) end create_setup_file end |
#load ⇒ Object
Retorna los datos del archivo de configuración
46 47 48 49 50 51 52 53 |
# File 'lib/common/setup.rb', line 46 def load if File.exist?(@setup_file_path) data = YAML.load(File.read(@setup_file_path)) JSON.parse(data.to_json, object_class: OpenStruct) else raise Liri::FileNotFoundError.new(@setup_file_path) end end |
#set(value, *keys) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/common/setup.rb', line 55 def set(value, *keys) data = YAML.load(File.read(@setup_file_path)) keys = keys.first aux = data keys.each_with_index do |key, index| if (keys[index + 1]) aux = data[key] else aux[key] = value end end File.open(@setup_file_path, 'w') { |f| f.write data.to_yaml } end |