Module: Stax

Defined in:
lib/stax/dsl.rb,
lib/stax/cli.rb,
lib/stax/git.rb,
lib/stax/iam.rb,
lib/stax/base.rb,
lib/stax/stack.rb,
lib/stax/aws/s3.rb,
lib/stax/aws/sg.rb,
lib/stax/cli/ls.rb,
lib/stax/docker.rb,
lib/stax/github.rb,
lib/stax/aws/acm.rb,
lib/stax/aws/alb.rb,
lib/stax/aws/asg.rb,
lib/stax/aws/cfn.rb,
lib/stax/aws/dms.rb,
lib/stax/aws/ec2.rb,
lib/stax/aws/ecr.rb,
lib/stax/aws/ecs.rb,
lib/stax/aws/elb.rb,
lib/stax/aws/emr.rb,
lib/stax/aws/iam.rb,
lib/stax/aws/kms.rb,
lib/stax/aws/rds.rb,
lib/stax/aws/sdk.rb,
lib/stax/aws/sqs.rb,
lib/stax/aws/ssm.rb,
lib/stax/aws/sts.rb,
lib/stax/cli/new.rb,
lib/stax/keypair.rb,
lib/stax/version.rb,
lib/stax/aws/logs.rb,
lib/stax/cli/crud.rb,
lib/stax/cli/info.rb,
lib/stax/mixin/s3.rb,
lib/stax/mixin/sg.rb,
lib/stax/staxfile.rb,
lib/stax/aws/apigw.rb,
lib/stax/mixin/acm.rb,
lib/stax/mixin/alb.rb,
lib/stax/mixin/asg.rb,
lib/stax/mixin/dms.rb,
lib/stax/mixin/ec2.rb,
lib/stax/mixin/ecr.rb,
lib/stax/mixin/ecs.rb,
lib/stax/mixin/elb.rb,
lib/stax/mixin/emr.rb,
lib/stax/mixin/kms.rb,
lib/stax/mixin/rds.rb,
lib/stax/mixin/sqs.rb,
lib/stax/mixin/ssh.rb,
lib/stax/mixin/ssm.rb,
lib/stax/stack/cfn.rb,
lib/stax/aws/lambda.rb,
lib/stax/generators.rb,
lib/stax/mixin/logs.rb,
lib/stax/stack/crud.rb,
lib/stax/subcommand.rb,
lib/stax/aws/keypair.rb,
lib/stax/aws/route53.rb,
lib/stax/cli/version.rb,
lib/stax/mixin/apigw.rb,
lib/stax/stack/drift.rb,
lib/stax/aws/dynamodb.rb,
lib/stax/aws/firehose.rb,
lib/stax/cli/generate.rb,
lib/stax/mixin/lambda.rb,
lib/stax/aws/codebuild.rb,
lib/stax/mixin/keypair.rb,
lib/stax/stack/exports.rb,
lib/stax/stack/outputs.rb,
lib/stax/aws/cloudfront.rb,
lib/stax/mixin/dynamodb.rb,
lib/stax/mixin/firehose.rb,
lib/stax/stack/template.rb,
lib/stax/generators/base.rb,
lib/stax/mixin/codebuild.rb,
lib/stax/stack/changeset.rb,
lib/stax/stack/resources.rb,
lib/stax/aws/codepipeline.rb,
lib/stax/mixin/cloudfront.rb,
lib/stax/mixin/ecs/deploy.rb,
lib/stax/stack/parameters.rb,
lib/stax/mixin/codepipeline.rb,
lib/stax/aws/secrets_manager.rb,
lib/stax/mixin/dynamodb/local.rb,
lib/stax/mixin/dynamodb/backup.rb,
lib/stax/mixin/secrets_manager.rb,
lib/stax/mixin/dynamodb/throughput.rb,
lib/stax/generators/new/new_generator.rb,
lib/stax/generators/stack/stack_generator.rb,
lib/stax/generators/new/templates/lib/stack.rb,
lib/stax/generators/generator/generator_generator.rb,
lib/stax/cfer.rb

Overview

Monkey-patches you may make to change stack behavior. Changing these here will affect all stacks. You may also define these per-stack in the sub-class for each stack in lib/stacks/.

Defined Under Namespace

Modules: Acm, Alb, Apigw, Asg, Aws, Cloudfront, Cmd, Codebuild, Codepipeline, Dms, Dsl, DynamoDB, Ec2, Ecr, Ecs, Elb, Emr, Firehose, Generators, Keypair, Kms, Lambda, Logs, Rds, S3, SecretsManager, Sg, Sqs, Ssh, Ssm Classes: Base, Cli, Docker, Git, Github, Iam, Stack, SubCommand

Constant Summary collapse

VERSION =
'0.1.12'
@@_root_path =
nil
@@_stack_list =
[]
@@_command_list =
[]

Class Method Summary collapse

Class Method Details

.add_command(name, klass = nil) ⇒ Object

add a non-stack command at top level



82
83
84
85
86
87
88
89
90
# File 'lib/stax/staxfile.rb', line 82

def self.add_command(name, klass = nil)
  @@_command_list << name

  ## class defaults to eg Stax::Name::Cmd
  klass ||= self.const_get(name.to_s.split(/[_-]/).map(&:capitalize).join + '::Cmd')

  Cli.desc(name, "#{name} commands")
  Cli.subcommand(name, klass)
end

.add_stack(name, opt = {}) ⇒ Object

add a stack by name, creates class as needed



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
# File 'lib/stax/staxfile.rb', line 54

def self.add_stack(name, opt = {})
  @@_stack_list << name

  ## camelize the stack name into class name
  c = name.to_s.split(/[_-]/).map(&:capitalize).join

  ## create the class if it does not exist yet
  if self.const_defined?(c)
    self.const_get(c)
  else
    self.const_set(c, Class.new(Stack))
  end.tap do |klass|
    Cli.desc("#{name} COMMAND", "#{name} stack commands")
    Cli.subcommand(name, klass)

    ## syntax to include mixins, reverse to give predictable include order
    opt.fetch(:include, []).reverse.each do |i|
      klass.include(self.const_get(i))
    end

    klass.instance_variable_set(:@name, name)
    klass.instance_variable_set(:@imports, Array(opt.fetch(:import, [])))
    klass.instance_variable_set(:@type, opt.fetch(:type, nil))
    klass.instance_variable_set(:@groups, opt.fetch(:groups, nil))
  end
end

.command_listObject

list of commands defined in Staxfile



17
18
19
# File 'lib/stax/staxfile.rb', line 17

def self.command_list
  @@_command_list
end

.find_staxfileObject

search up the dir tree for nearest Staxfile



22
23
24
25
26
# File 'lib/stax/staxfile.rb', line 22

def self.find_staxfile
  Pathname.pwd.ascend do |path|
    return path if File.exist?(file = path.join('Staxfile'))
  end
end

.load_staxfileObject



28
29
30
31
32
33
34
35
# File 'lib/stax/staxfile.rb', line 28

def self.load_staxfile
  @@_root_path = find_staxfile
  if root_path
    load(root_path.join('Staxfile'))
    require_stacks
    require_commands
  end
end

.require_commandsObject

auto-require any command lib files



46
47
48
49
50
51
# File 'lib/stax/staxfile.rb', line 46

def self.require_commands
  command_list.each do |command|
    f = root_path.join('lib', "#{command}.rb")
    require(f) if File.exist?(f)
  end
end

.require_stacksObject

auto-require any stack lib files



38
39
40
41
42
43
# File 'lib/stax/staxfile.rb', line 38

def self.require_stacks
  stack_list.each do |stack|
    f = root_path.join('lib', 'stack', "#{stack}.rb")
    require(f) if File.exist?(f)
  end
end

.root_pathObject

the stax root is defined as location of Staxfile



7
8
9
# File 'lib/stax/staxfile.rb', line 7

def self.root_path
  @@_root_path
end

.stack_listObject

list of stacks defined in Staxfile



12
13
14
# File 'lib/stax/staxfile.rb', line 12

def self.stack_list
  @@_stack_list
end