Class: AwsSamYarnBuilder::Build

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Build



3
4
5
# File 'lib/aws_sam_yarn_builder/build.rb', line 3

def initialize(options = {})
  self.options = options
end

Instance Method Details

#build!Object



7
8
9
10
11
12
13
# File 'lib/aws_sam_yarn_builder/build.rb', line 7

def build!
  if options[:function]
    build_single_function!
  else
    build_full_template!
  end
end

#build_full_template!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aws_sam_yarn_builder/build.rb', line 15

def build_full_template!
  reset_build_dir!
  reset_staging_dir!

  local_dependencies = template.function_resources.map do |function|
    get_local_file_dependencies(function)
  end.flatten.uniq.compact

  local_dependencies.each do |d|
    d.pack destination_staging_dir
  end

  template.function_resources.each do |function|
    package = package_from_function(function)

    package.pack destination_staging_dir
    package.build function.name, destination_dir, destination_staging_dir
  end

  template.write_to_output(destination_dir, template_base_dir)

  FileUtils.rm_rf(destination_staging_dir)
end

#build_single_function!Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aws_sam_yarn_builder/build.rb', line 39

def build_single_function!
  reset_build_dir!
  reset_staging_dir!

  function_resource = template.function_resource_by_logical_id(options[:function])

  if function_resource
    local_dependencies = get_local_file_dependencies(function_resource).flatten.uniq.compact

    local_dependencies.each do |d|
      d.pack destination_staging_dir
    end

    package = package_from_function(function_resource)

    package.pack destination_staging_dir
    package.build function_resource.name, destination_dir, destination_staging_dir

    FileUtils.rm_rf(destination_staging_dir)
  end
end