Class: Ufo::Setting::Profile
- Inherits:
-
Object
- Object
- Ufo::Setting::Profile
- Extended by:
- Memoist
- Defined in:
- lib/ufo/setting/profile.rb
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(type, profile = nil) ⇒ Profile
constructor
A new instance of Profile.
- #yaml_load(text) ⇒ Object
Constructor Details
#initialize(type, profile = nil) ⇒ Profile
Returns a new instance of Profile.
5 6 7 8 |
# File 'lib/ufo/setting/profile.rb', line 5 def initialize(type, profile=nil) @type = type.to_s # cfn or network @profile = profile end |
Instance Method Details
#data ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ufo/setting/profile.rb', line 10 def data names = [ @profile, # user specified Ufo.env, # conventional based on env "default", # fallback to default "base", # finally fallback to base ].compact.uniq paths = names.map { |name| "#{Ufo.root}/.ufo/settings/#{@type}/#{name}.yml" } found = paths.find { |p| File.exist?(p) } unless found puts "#{@type.camelize} profile not found. Please double check that it exists. Checked paths: #{paths}" exit 1 end text = RenderMePretty.result(found) specific_data = yaml_load(text) base = "#{Ufo.root}/.ufo/settings/#{@type}/base.yml" base_data = if File.exist?(base) text = RenderMePretty.result(base) yaml_load(text) else {} end base_data.deep_merge(specific_data) end |
#yaml_load(text) ⇒ Object
39 40 41 42 |
# File 'lib/ufo/setting/profile.rb', line 39 def yaml_load(text) result = YAML.load(text) # yaml file can contain nothing but comments result.is_a?(Hash) ? result.deep_symbolize_keys : {} end |