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.
-
#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) ⇒ 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) ⇒ Setup
Returns a new instance of Setup.
19 20 21 22 23 24 25 |
# File 'lib/common/setup.rb', line 19 def initialize(destination_folder_path) @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) @agent_folder_path = File.join(@setup_folder_path, '/', AGENT_FOLDER_NAME) 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 |
#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
59 60 61 62 63 64 65 66 |
# File 'lib/common/setup.rb', line 59 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
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/common/setup.rb', line 78 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
93 94 95 96 97 98 99 100 |
# File 'lib/common/setup.rb', line 93 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
68 69 70 71 72 73 74 75 |
# File 'lib/common/setup.rb', line 68 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
27 28 29 30 31 32 33 |
# File 'lib/common/setup.rb', line 27 def init create_folder(@setup_folder_path) create_folder(@logs_folder_path) create_folder(@manager_folder_path) create_folder(@agent_folder_path) create_setup_file end |
#load ⇒ Object
Retorna los datos del archivo de configuración
36 37 38 39 40 41 42 43 |
# File 'lib/common/setup.rb', line 36 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
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/common/setup.rb', line 45 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 |