Class: HR_Deploy::ConfigHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/hr_deploy/config_handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject

Returns the value of attribute error.



83
84
85
# File 'lib/hr_deploy/config_handler.rb', line 83

def error
  @error
end

#targetsObject

Returns the value of attribute targets.



84
85
86
# File 'lib/hr_deploy/config_handler.rb', line 84

def targets
  @targets
end

Class Method Details

.config_exists?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/hr_deploy/config_handler.rb', line 92

def self.config_exists?
  File.exists?(CONFIG_FILE_NAME)
end

Instance Method Details

#attempt_to_load_targetsObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/hr_deploy/config_handler.rb', line 113

def attempt_to_load_targets
  # If any of the checks fail, 'self.error' will be set
  # If no checks fail, 'self.targets' will be set

  if valid_format?
    if valid_structure?
      self.targets = load_targets
    end
  end
end

#generate_configObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/hr_deploy/config_handler.rb', line 96

def generate_config
  generate = true

  if self.class.config_exists?
    print 'Config file already exists. Overwrite? [Y/n] > '
    answer = $stdin.gets.chomp.downcase
    generate = false unless answer == 'y' || answer == 'yes'
  end

  if generate
    File.open(CONFIG_FILE_NAME, 'w') { |file| file.write(EXAMPLE_CONFIG) }
    puts "Example config created at #{CONFIG_FILE_NAME}. Edit it to suit your needs"
  else
    puts 'Not overwriting config'
  end
end

#newObject



86
87
88
89
90
# File 'lib/hr_deploy/config_handler.rb', line 86

def new
  @error = nil
  @raw_targets = nil
  @targets = []
end