Class: Vx::Builder::BuildConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/vx/builder/build_configuration.rb,
lib/vx/builder/build_configuration/env.rb,
lib/vx/builder/build_configuration/cache.rb,
lib/vx/builder/build_configuration/vexor.rb,
lib/vx/builder/build_configuration/deploy.rb,
lib/vx/builder/build_configuration/matrix.rb,
lib/vx/builder/build_configuration/deploy/base.rb,
lib/vx/builder/build_configuration/deploy/shell.rb

Defined Under Namespace

Classes: Cache, Deploy, Env, Matrix, Vexor

Constant Summary collapse

REQUIRED_KEYS =
%w{
  rvm
  scala
  jdk
  go
  node_js
  rust
  python

  language
  script
}
ATTRIBUTES =
%w{
  rvm
  scala
  jdk
  go
  node_js
  rust
  python

  language
  gemfile
  services
  image

  bundler_args
  pip_args

  before_install
  install
  before_script
  script
  after_success

  before_deploy
  after_deploy

  workdir

  parallel
  parallel_job_number

  database
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_attributes = {}, matrix_attributes = {}) ⇒ BuildConfiguration

Returns a new instance of BuildConfiguration.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



71
72
73
# File 'lib/vx/builder/build_configuration.rb', line 71

def attributes
  @attributes
end

#cacheObject (readonly)

Returns the value of attribute cache.



71
72
73
# File 'lib/vx/builder/build_configuration.rb', line 71

def cache
  @cache
end

#deployObject (readonly)

Returns the value of attribute deploy.



71
72
73
# File 'lib/vx/builder/build_configuration.rb', line 71

def deploy
  @deploy
end

#deploy_modulesObject (readonly)

Returns the value of attribute deploy_modules.



71
72
73
# File 'lib/vx/builder/build_configuration.rb', line 71

def deploy_modules
  @deploy_modules
end

#envObject (readonly)

Returns the value of attribute env.



71
72
73
# File 'lib/vx/builder/build_configuration.rb', line 71

def env
  @env
end

#matrixObject (readonly)

Returns the value of attribute matrix.



71
72
73
# File 'lib/vx/builder/build_configuration.rb', line 71

def matrix
  @matrix
end

#vexorObject (readonly)

Returns the value of attribute vexor.



71
72
73
# File 'lib/vx/builder/build_configuration.rb', line 71

def vexor
  @vexor
end

Class Method Details

.from_file(file) ⇒ Object



64
65
66
67
68
# 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) ⇒ Object



59
60
61
62
# File 'lib/vx/builder/build_configuration.rb', line 59

def from_yaml(yaml)
  hash = YAML.load(yaml)
  new hash
end

Instance Method Details

#any?Boolean

have any required attributes

Returns:

  • (Boolean)


105
106
107
108
109
# File 'lib/vx/builder/build_configuration.rb', line 105

def any?
  REQUIRED_KEYS.any? do |key|
    attributes[key].any?
  end
end

#cached_directoriesObject



189
190
191
# File 'lib/vx/builder/build_configuration.rb', line 189

def cached_directories
  cache.enabled? and cache.directories
end

#database?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/vx/builder/build_configuration.rb', line 173

def database?
  @attributes['database'].first != false
end

#deploy?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/vx/builder/build_configuration.rb', line 129

def deploy?
  deploy.attributes.any?
end

#deploy_modules?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/vx/builder/build_configuration.rb', line 133

def deploy_modules?
  deploy_modules.any?
end

#empty?Boolean

nil or empty configuration file

Returns:

  • (Boolean)


100
101
102
# File 'lib/vx/builder/build_configuration.rb', line 100

def empty?
  @is_empty
end

#env_matrixObject



161
162
163
# File 'lib/vx/builder/build_configuration.rb', line 161

def env_matrix
  env.matrix
end

#flat_matrix_attributesObject

for deploy builder



112
113
114
# File 'lib/vx/builder/build_configuration.rb', line 112

def flat_matrix_attributes
  @matrix_attributes
end

#languageObject



165
166
167
# File 'lib/vx/builder/build_configuration.rb', line 165

def language
  @attributes["language"].first
end

#matrix_attributesObject



116
117
118
119
120
121
122
123
124
125
126
127
# 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_idObject

for tests



138
139
140
# File 'lib/vx/builder/build_configuration.rb', line 138

def matrix_id
  matrix_attributes.to_a.map{|i| i.join(":") }.sort.join(", ")
end

#parallelObject



169
170
171
# File 'lib/vx/builder/build_configuration.rb', line 169

def parallel
  @attributes["parallel"].first.to_i
end

#parallel?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/vx/builder/build_configuration.rb', line 177

def parallel?
  parallel > 0
end

#parallel_job_numberObject



181
182
183
# File 'lib/vx/builder/build_configuration.rb', line 181

def parallel_job_number
  @attributes["parallel_job_number"].first.to_i
end

#parallel_job_number?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/vx/builder/build_configuration.rb', line 185

def parallel_job_number?
  parallel_job_number > 0
end

#to_hashObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# 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_yamlObject



157
158
159
# File 'lib/vx/builder/build_configuration.rb', line 157

def to_yaml
  to_hash.to_yaml
end