Class: Stackup::RakeTasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/stackup/rake_tasks.rb

Overview

Declare Rake tasks for managing a stack.

Defined Under Namespace

Classes: DataOption, DataOptionArray, DataOptionFile, DataOptionHash

Constant Summary collapse

STACKUP_CLI =

path to the “stackup” executable

File.expand_path("../../bin/stackup", __dir__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, template = nil) {|_self| ... } ⇒ RakeTasks

Returns a new instance of RakeTasks.

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
# File 'lib/stackup/rake_tasks.rb', line 23

def initialize(name, template = nil)
  @name = name
  @stack = name
  @template = template
  yield self if block_given?
  raise ArgumentError, "no name provided" unless @name
  raise ArgumentError, "no template provided" unless @template

  define
end

Instance Attribute Details

#capabilitiesObject

Returns the value of attribute capabilities.



19
20
21
# File 'lib/stackup/rake_tasks.rb', line 19

def capabilities
  @capabilities
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/stackup/rake_tasks.rb', line 14

def name
  @name
end

#parametersObject

Returns the value of attribute parameters.



17
18
19
# File 'lib/stackup/rake_tasks.rb', line 17

def parameters
  @parameters
end

#stackObject

Returns the value of attribute stack.



15
16
17
# File 'lib/stackup/rake_tasks.rb', line 15

def stack
  @stack
end

#tagsObject

Returns the value of attribute tags.



18
19
20
# File 'lib/stackup/rake_tasks.rb', line 18

def tags
  @tags
end

#templateObject

Returns the value of attribute template.



16
17
18
# File 'lib/stackup/rake_tasks.rb', line 16

def template
  @template
end

Instance Method Details

#defineObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/stackup/rake_tasks.rb', line 41

def define
  namespace(name) do

    data_options = [DataOption.for("--template", template)]
    data_options << DataOption.for("--parameters", parameters) if parameters
    data_options << DataOption.for("--tags", tags) if tags

    desc "Update #{stack} stack"
    task "up" => data_options.grep(DataOptionFile).map(&:argument) do
      data_options << DataOption.for("--capability", capabilities) if capabilities
      stackup "up", *data_options.map(&:to_a).flatten
    end

    desc "Cancel update of #{stack} stack"
    task "cancel" do
      stackup "cancel-update"
    end

    desc "Show pending changes to #{stack} stack"
    task "diff" => data_options.grep(DataOptionFile).map(&:argument) do
      stackup "diff", *data_options.map(&:to_a).flatten
    end

    desc "Show #{stack} stack outputs and resources"
    task "inspect" do
      stackup "inspect"
    end

    desc "Show #{stack} stack outputs only"
    task "outputs" do
      stackup "outputs"
    end

    desc "Delete #{stack} stack"
    task "down" do
      stackup "down"
    end

  end
end

#stackup(*rest) ⇒ Object



37
38
39
# File 'lib/stackup/rake_tasks.rb', line 37

def stackup(*rest)
  sh STACKUP_CLI, "-Y", stack, *rest
end