Module: Forger::Template::Helper::CoreHelper
- Included in:
- Forger::Template::Helper
- Defined in:
- lib/forger/template/helper/core_helper.rb
Instance Method Summary collapse
-
#layout_path(name = "default") ⇒ Object
Get full path of layout from layout name.
-
#settings ⇒ Object
provides access to config/settings.yml as variables.
-
#timestamp ⇒ Object
pretty timestamp that is useful for ami ids.
-
#user_data(name, base64: true, layout: "default") ⇒ Object
assuming user-data script is a bash script for simplicity for now.
-
#vars ⇒ Object
(also: #variables)
provides access to config/* settings as variables FORGER_ENV=development => config/variables/development.rb FORGER_ENV=production => config/variables/production.rb.
Instance Method Details
#layout_path(name = "default") ⇒ Object
Get full path of layout from layout name
layout_name=false - dont use layout at all
layout_name=nil - default to default.sh layout if available
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/forger/template/helper/core_helper.rb', line 38 def layout_path(name="default") return false if name == false # disable layout name = "default" if name.nil? # in case user passes in nil ext = File.extname(name) name += ".sh" if ext.empty? layout_path = "#{Forger.root}/app/user_data/layouts/#{name}" # special rule for default in case there's no default layout if name.include?("default") and !File.exist?(layout_path) return false end # other named layouts should error if it doesnt exit unless File.exist?(layout_path) puts "ERROR: Layout #{layout_path} does not exist. Are you sure it exists? Exiting".color(:red) exit 1 end layout_path end |
#settings ⇒ Object
provides access to config/settings.yml as variables
69 70 71 |
# File 'lib/forger/template/helper/core_helper.rb', line 69 def settings Forger.settings end |
#timestamp ⇒ Object
pretty timestamp that is useful for ami ids. the timestamp is generated once and cached.
75 76 77 |
# File 'lib/forger/template/helper/core_helper.rb', line 75 def @timestamp ||= Time.now.strftime("%Y-%m-%d-%H-%M-%S") end |
#user_data(name, base64: true, layout: "default") ⇒ Object
assuming user-data script is a bash script for simplicity for now
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/forger/template/helper/core_helper.rb', line 6 def user_data(name, base64:true, layout:"default") name = normalize_user_data_name_input(name) layout_path = layout_path(layout) path = "#{Forger.root}/app/user_data/#{name}" unless File.exist?(path) puts "ERROR: user-data script #{path.color(:red)} does not exist" exit 1 end result = RenderMePretty.result(path, context: self, layout: layout_path) # Must prepend and append scripts in user_data here because we need to # encode the user_data script for valid yaml to load in the profile. # Tried moving this logic to the params but that is too late and produces # invalid yaml. Unless we want to encode and dedode twice. scripts = [result] scripts = prepend_scripts(scripts) scripts = append_scripts(scripts) divider = "\n############################## DIVIDER ##############################\n" result = scripts.join(divider) # save the unencoded user-data script for easy debugging temp_path = "#{Forger.build_root}/user-data.txt" FileUtils.mkdir_p(File.dirname(temp_path)) IO.write(temp_path, result) base64 ? Base64.encode64(result).strip : result end |
#vars ⇒ Object Also known as: variables
provides access to config/* settings as variables
FORGER_ENV=development => config/variables/development.rb
FORGER_ENV=production => config/variables/production.rb
63 64 65 |
# File 'lib/forger/template/helper/core_helper.rb', line 63 def vars Forger.vars end |