Class: AwsSamYarnBuilder::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_sam_yarn_builder/template.rb

Defined Under Namespace

Classes: FunctionResource

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, contents) ⇒ Template



40
41
42
43
# File 'lib/aws_sam_yarn_builder/template.rb', line 40

def initialize(path, contents)
  self.path = path
  self.contents = contents
end

Class Method Details

.extract_from_file!(file_path) ⇒ Object



36
37
38
# File 'lib/aws_sam_yarn_builder/template.rb', line 36

def self.extract_from_file!(file_path)
  new file_path, File.read(file_path)
end

Instance Method Details

#function_resource_by_logical_id(logical_id) ⇒ Object



59
60
61
62
63
# File 'lib/aws_sam_yarn_builder/template.rb', line 59

def function_resource_by_logical_id(logical_id)
  raw_function_resource = raw_function_resources.detect { |name, options| name == logical_id }

  FunctionResource.new(raw_function_resource.first, raw_function_resource.last["Properties"])
end

#function_resourcesObject



55
56
57
# File 'lib/aws_sam_yarn_builder/template.rb', line 55

def function_resources
  @function_resources ||= raw_function_resources.map { |name, options| FunctionResource.new(name, options["Properties"]) }
end

#transformObject



51
52
53
# File 'lib/aws_sam_yarn_builder/template.rb', line 51

def transform
  document["Transform"]
end

#write_to_output(output, source_directory) ⇒ Object



45
46
47
48
49
# File 'lib/aws_sam_yarn_builder/template.rb', line 45

def write_to_output(output, source_directory)
  File.open(File.join(output, "template.yaml"), "w+") do |file|
    file << transformed_contents(source_directory)
  end
end