class Vx::Builder::BuildConfiguration

Constants

ATTRIBUTES
REQUIRED_KEYS

Attributes

attributes[R]
cache[R]
deploy[R]
deploy_modules[R]
env[R]
matrix[R]
vexor[R]

Public Class Methods

from_file(file) click to toggle source
# File lib/vx/builder/build_configuration.rb, line 64
def from_file(file)
  if File.readable? file
    from_yaml File.read(file)
  end
end
from_yaml(yaml) click to toggle source
# File lib/vx/builder/build_configuration.rb, line 59
def from_yaml(yaml)
  hash = YAML.load(yaml)
  new hash
end
new(new_attributes = {}, matrix_attributes = {}) click to toggle source
# File lib/vx/builder/build_configuration.rb, line 74
def initialize(new_attributes = {}, matrix_attributes = {})
  new_attributes = {} unless new_attributes.is_a?(Hash)

  @is_empty            = new_attributes == {}
  @env                 = Env.new       new_attributes.delete("env")
  @cache               = Cache.new     new_attributes.delete("cache")
  @vexor               = Vexor.new     new_attributes.delete("vexor")
  @matrix              = Matrix.new    new_attributes.delete("matrix")

  @deploy              = Deploy.new    new_attributes.delete("deploy")
  @deploy_modules      = new_attributes.delete("deploy_modules") || []
  @deploy_modules      = Deploy.restore_modules(@deploy_modules)

  @matrix_attributes   = matrix_attributes.inject({}) do |a, pair|
    k,v = pair
    if k == 'parallel_job_number'
      k = 'parallel'
    end
    a[k] = v
    a
  end

  build_attributes new_attributes
end

Public Instance Methods

any?() click to toggle source

have any required attributes

# File lib/vx/builder/build_configuration.rb, line 105
def any?
  REQUIRED_KEYS.any? do |key|
    attributes[key].any?
  end
end
cached_directories() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 189
def cached_directories
  cache.enabled? and cache.directories
end
database?() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 173
def database?
  @attributes['database'].first != false
end
deploy?() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 129
def deploy?
  deploy.attributes.any?
end
deploy_modules?() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 133
def deploy_modules?
  deploy_modules.any?
end
empty?() click to toggle source

nil or empty configuration file

# File lib/vx/builder/build_configuration.rb, line 100
def empty?
  @is_empty
end
env_matrix() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 161
def env_matrix
  env.matrix
end
flat_matrix_attributes() click to toggle source

for deploy builder

# File lib/vx/builder/build_configuration.rb, line 112
def flat_matrix_attributes
  @matrix_attributes
end
language() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 165
def language
  @attributes["language"].first
end
matrix_attributes() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 116
def matrix_attributes
  @matrix_attributes.inject({}) do |a,pair|
    k,v = pair
    if k == 'env'
      v = v["matrix"].first
    end
    if v
      a[k] = v
    end
    a
  end
end
matrix_id() click to toggle source

for tests

# File lib/vx/builder/build_configuration.rb, line 138
def matrix_id
  matrix_attributes.to_a.map{|i| i.join(":") }.sort.join(", ")
end
parallel() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 169
def parallel
  @attributes["parallel"].first.to_i
end
parallel?() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 177
def parallel?
  parallel > 0
end
parallel_job_number() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 181
def parallel_job_number
  @attributes["parallel_job_number"].first.to_i
end
parallel_job_number?() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 185
def parallel_job_number?
  parallel_job_number > 0
end
to_hash() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 142
def to_hash
  if empty?
    {}
  else
    attributes.merge(
      "env"            => env.attributes,
      "cache"          => cache.attributes,
      "vexor"          => vexor.attributes,
      "matrix"         => matrix.attributes,
      "deploy"         => deploy.attributes,
      "deploy_modules" => deploy_modules.map(&:to_hash)
    )
  end
end
to_yaml() click to toggle source
# File lib/vx/builder/build_configuration.rb, line 157
def to_yaml
  to_hash.to_yaml
end

Private Instance Methods

build_attributes(new_attributes) click to toggle source
# File lib/vx/builder/build_configuration.rb, line 201
def build_attributes(new_attributes)
  @attributes = ATTRIBUTES.inject({}) do |ac, attribute_name|
    attribute = new_attributes[attribute_name]
    ac[attribute_name] = Array(attribute)
    ac
  end
end