Class: Travis::Yaml::Matrix

Inherits:
Array
  • Object
show all
Defined in:
lib/travis/yaml/matrix.rb

Defined Under Namespace

Classes: Entry

Constant Summary collapse

EXPAND_KEYS =
[
  :compiler, :gemfile, :ghc, :go, :jdk, :lein, :node_js, :otp_release,
  :perl, :php, :python, :ruby, :scala, :xcode_scheme, :xcode_sdk, :os
]
KEYS =
EXPAND_KEYS + [:env]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Matrix

Returns a new instance of Matrix.



30
31
32
33
# File 'lib/travis/yaml/matrix.rb', line 30

def initialize(root)
  @root = root
  super(entries)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



28
29
30
# File 'lib/travis/yaml/matrix.rb', line 28

def root
  @root
end

Instance Method Details

#axesObject



35
36
37
38
39
40
# File 'lib/travis/yaml/matrix.rb', line 35

def axes
  @axes ||= KEYS.select do |key|
    next true if values_for(key) and values_for(key).size > 1
    root.matrix.include.any? { |i| i[key] } if root.matrix and root.matrix.include
  end
end

#entriesObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/travis/yaml/matrix.rb', line 42

def entries
  @entries ||= begin
    first, *rest = axes.map { |k| values_for(k) || [nil] }
    entries      = Array(first).product(*rest).map { |list| Hash[axes.zip(list)] }
    if m = root.matrix
      entries.delete_if { |e| m.exclude.any? { |p| p.all? { |k,v| e[k.to_sym] == v } } } if m.exclude
      m.include.each { |i| entries << Hash[axes.map { |k| [k, i[k]] }] } if m.include
    end
    entries.map! { |attributes| Entry.new(root, attributes) }
    entries.any? ? entries : [Entry.new(root, {})]
  end
end

#values_for(key) ⇒ Object



55
56
57
58
# File 'lib/travis/yaml/matrix.rb', line 55

def values_for(key)
  return root[key] unless key == :env
  root.env.matrix if root.env
end