Class: Balancer::Profile
- Inherits:
-
Base
- Object
- Base
- Balancer::Profile
show all
- Includes:
- Template
- Defined in:
- lib/balancer/profile.rb
Instance Method Summary
collapse
Methods inherited from Base
#derandomize, #initialize, #randomize
Constructor Details
This class inherits a constructor from Balancer::Base
Instance Method Details
#check! ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/balancer/profile.rb', line 14
def check!
file = profile_file(profile_name)
return if File.exist?(file)
puts "Unable to find a #{file.colorize(:green)} profile file."
puts "Please double check that it exists or that you specified the right profile.".colorize(:red)
exit 1
end
|
#load ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/balancer/profile.rb', line 5
def load
return @profile_params if @profile_params
check!
file = profile_file(profile_name)
@profile_params = load_profile(file)
end
|
#load_profile(file) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/balancer/profile.rb', line 23
def load_profile(file)
return {} unless File.exist?(file)
puts "Using profile: #{file}".colorize(:green)
text = RenderMePretty.result(file, context: context)
begin
data = YAML.load(text)
rescue Psych::SyntaxError => e
tmp_file = file.sub(".balancer", "tmp")
FileUtils.mkdir_p(File.dirname(tmp_file))
IO.write(tmp_file, text)
puts "There was an error evaluating in your yaml file #{file}".colorize(:red)
puts "The evaludated yaml file has been saved at #{tmp_file} for debugging."
puts "ERROR: #{e.message}"
exit 1
end
data ? data : {} data.has_key?("create_load_balancer") ? data["create_load_balancer"] : data
end
|
#profile_file(name) ⇒ Object
61
62
63
|
# File 'lib/balancer/profile.rb', line 61
def profile_file(name)
"#{Balancer.root}/.balancer/#{name}.yml"
end
|
#profile_name ⇒ Object
Determines a valid profile_name. Falls back to default
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/balancer/profile.rb', line 44
def profile_name
if @options[:profile] && File.exist?(@options[:profile])
filename_profile = File.basename(@options[:profile], '.yml')
end
name = derandomize(@name)
if File.exist?(profile_file(name))
name_profile = name
end
filename_profile ||
@options[:profile] ||
name_profile || "default"
end
|