Module: Cfer::Auster::CferHelpers

Defined in:
lib/cfer/auster/cfer_helpers.rb

Defined Under Namespace

Classes: Cfizer

Constant Summary collapse

CFIZER_DEFAULT_CAPTURE_REGEXP =
/C\{(?<directive>.*?)\}/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cfize(text, capture_regexp: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cfer/auster/cfer_helpers.rb', line 26

def self.cfize(text, capture_regexp: nil)
  raise "'text' must be a string." unless text.is_a?(String)

  capture_regexp ||= CFIZER_DEFAULT_CAPTURE_REGEXP

  raise "'capture_regexp' must be a Regexp." unless capture_regexp.is_a?(Regexp)
  raise "'capture_regexp' must include a 'contents' named 'directive'." \
    unless capture_regexp.named_captures.key?("directive")

  working = []
  until working[-2] == "" && working[-1] == "" do
    if working.empty?
      working = text.partition(capture_regexp)
    else
      working[-1] = working[-1].partition(capture_regexp)
      working = working.flatten
    end
  end

  cfizer = Cfizer.new
  Cfizer::Fn.join("", working.map do |token|
    match = capture_regexp.match(token)
    if match.nil?
      token
    else
      cfizer.cfize(match["directive"])
    end
  end.reject { |t| t == ""})
end

Instance Method Details

#_exported_name(name) ⇒ Object



18
19
20
# File 'lib/cfer/auster/cfer_helpers.rb', line 18

def _exported_name(name)
  "#{parameters[:PlanID]}--#{name}"
end

#cfize(text, capture_regexp: nil) ⇒ Object



22
23
24
# File 'lib/cfer/auster/cfer_helpers.rb', line 22

def cfize(text, capture_regexp: nil)
  CferHelpers.cfize(text, capture_regexp: capture_regexp)
end

#eval_file(filename) ⇒ Object



6
7
8
# File 'lib/cfer/auster/cfer_helpers.rb', line 6

def eval_file(filename)
  instance_eval IO.read(filename), filename
end

#export(name, value) ⇒ Object



14
15
16
# File 'lib/cfer/auster/cfer_helpers.rb', line 14

def export(name, value)
  output name, value, Export: { Name: _exported_name(name) }
end

#import(name) ⇒ Object



10
11
12
# File 'lib/cfer/auster/cfer_helpers.rb', line 10

def import(name)
  { "Fn::ImportValue" => _exported_name(name) }
end