module Stax

Staxfile DSL commands

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/.

generator to create the basic files for one or more new stacks:

- add stack to Staxfile
- subclass in lib/stack/
- cfer/json/yaml template outline in cf/

Constants

VERSION

Public Class Methods

add_command(name, klass = nil) click to toggle source

add a non-stack command at top level

# 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 = {}) click to toggle source

add a stack by name, creates class as needed

# 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_list() click to toggle source

list of commands defined in Staxfile

# File lib/stax/staxfile.rb, line 17
def self.command_list
  @@_command_list
end
find_staxfile() click to toggle source

search up the dir tree for nearest Staxfile

# 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_staxfile() click to toggle source
# 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_commands() click to toggle source

auto-require any command lib files

# 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_stacks() click to toggle source

auto-require any stack lib files

# 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_path() click to toggle source

the stax root is defined as location of Staxfile

# File lib/stax/staxfile.rb, line 7
def self.root_path
  @@_root_path
end
stack_list() click to toggle source

list of stacks defined in Staxfile

# File lib/stax/staxfile.rb, line 12
def self.stack_list
  @@_stack_list
end