Class: Ufo::DSL::Helper
- Inherits:
-
Object
- Object
- Ufo::DSL::Helper
- Defined in:
- lib/ufo/dsl/helper.rb
Overview
provides some helperally context variables
Instance Method Summary collapse
- #current_region ⇒ Object
-
#dockerfile_port ⇒ Object
helper variables.
- #env_file(path) ⇒ Object
-
#env_vars(text) ⇒ Object
helper methods.
- #filtered_lines(text) ⇒ Object
- #full_image_name ⇒ Object
-
#initialize(options = {}) ⇒ Helper
constructor
A new instance of Helper.
- #parse_for_dockerfile_port(dockerfile_path) ⇒ Object
- #setting ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Helper
Returns a new instance of Helper.
11 12 13 |
# File 'lib/ufo/dsl/helper.rb', line 11 def initialize(={}) @options = end |
Instance Method Details
#current_region ⇒ Object
61 62 63 64 |
# File 'lib/ufo/dsl/helper.rb', line 61 def current_region return 'us-east-1' if ENV['TEST'] @current_region ||= `aws configure get region`.strip rescue 'us-east-1' end |
#dockerfile_port ⇒ Object
helper variables
17 18 19 20 21 22 |
# File 'lib/ufo/dsl/helper.rb', line 17 def dockerfile_port dockerfile_path = "#{Ufo.root}/Dockerfile" if File.exist?(dockerfile_path) parse_for_dockerfile_port(dockerfile_path) end end |
#env_file(path) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/ufo/dsl/helper.rb', line 51 def env_file(path) full_path = "#{Ufo.root}/#{path}" unless File.exist?(full_path) puts "The #{full_path} env file could not be found. Are you sure it exists?" exit 1 end text = IO.read(full_path) env_vars(text) end |
#env_vars(text) ⇒ Object
helper methods
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ufo/dsl/helper.rb', line 30 def env_vars(text) lines = filtered_lines(text) lines.map do |line| key,value = line.strip.split("=").map {|x| x.strip} { name: key, value: value, } end end |
#filtered_lines(text) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/ufo/dsl/helper.rb', line 41 def filtered_lines(text) lines = text.split("\n") # remove comment at the end of the line lines.map! { |l| l.sub(/#.*/,'').strip } # filter out commented lines lines = lines.reject { |l| l =~ /(^|\s)#/i } # filter out empty lines lines = lines.reject { |l| l.strip.empty? } end |
#full_image_name ⇒ Object
24 25 26 |
# File 'lib/ufo/dsl/helper.rb', line 24 def full_image_name Docker::Builder.new(@options).full_image_name end |
#parse_for_dockerfile_port(dockerfile_path) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/ufo/dsl/helper.rb', line 70 def parse_for_dockerfile_port(dockerfile_path) lines = IO.read(dockerfile_path).split("\n") expose_line = lines.find { |l| l =~ /^EXPOSE / } if expose_line md = expose_line.match(/EXPOSE (\d+)/) port = md[1] if md end port.to_i if port end |