module What

Attributes

env[R]
matrix[R]
where[R]

Public Class Methods

info() click to toggle source
# File lib/what.rb, line 36
def info
  return unless Doit.options[:verbose]

  My.verbose "where", @where
  My.verbose "matrix", @matrix
  My.verbose "env", @env
end
init(config) click to toggle source
# File lib/what.rb, line 10
def init(config)
  @matrix = nil
  @yml = (config && YAML.load(config)) || {}

  @where = @yml.delete("where")
  @env = @yml.delete("env")
  @env ||= [""]
  @env = [@env].flatten.compact

  remote = Doit.options[:remote]
  @where = remote if remote && remote != "---"
  @where ||= Dir.pwd # default is current directory
  @where = [@where].flatten.compact

  build_matrix
  @matrix ||= []
  @matrix = [@matrix] unless @matrix.first.is_a?(Array)
  @matrix.map! { |m| m.flatten.inject({}) { |hsh, h| hsh.merge(h) } }
  info
end
to_env(hsh) click to toggle source
# File lib/what.rb, line 31
def to_env(hsh)
  arr = hsh.collect { |key, value| "#{key.to_s.upcase}=#{value}" }
  arr.join " "
end

Private Class Methods

add_to_matrix(key, val) click to toggle source
# File lib/what.rb, line 55
def add_to_matrix(key, val)
  arr = val.is_a?(Array) ?
    val.collect { |v| [{key => v}] } :
    [{key => val}]
  @matrix = @matrix ? @matrix.product(arr) : arr
end
build_matrix() click to toggle source
# File lib/what.rb, line 46
def build_matrix
  return if @yml.empty?

  key, value = @yml.first
  @yml.delete(key)
  add_to_matrix(key, value)
  build_matrix
end