Module: Travis::Yaml

Extended by:
Helper::Deyaml
Defined in:
lib/travis/yaml.rb,
lib/travis/yaml/web.rb,
lib/travis/yaml/errors.rb,
lib/travis/yaml/matrix.rb,
lib/travis/yaml/version.rb,
lib/travis/yaml/doc/value.rb,
lib/travis/yaml/doc/change.rb,
lib/travis/yaml/spec/def/os.rb,
lib/travis/yaml/doc/spec/map.rb,
lib/travis/yaml/doc/spec/seq.rb,
lib/travis/yaml/doc/validate.rb,
lib/travis/yaml/helper/merge.rb,
lib/travis/yaml/spec/def/env.rb,
lib/travis/yaml/spec/def/git.rb,
lib/travis/yaml/spec/def/job.rb,
lib/travis/yaml/doc/spec/node.rb,
lib/travis/yaml/doc/value/map.rb,
lib/travis/yaml/doc/value/seq.rb,
lib/travis/yaml/helper/common.rb,
lib/travis/yaml/helper/deyaml.rb,
lib/travis/yaml/helper/expand.rb,
lib/travis/yaml/spec/def/dist.rb,
lib/travis/yaml/spec/def/jdks.rb,
lib/travis/yaml/spec/def/root.rb,
lib/travis/yaml/spec/def/sudo.rb,
lib/travis/yaml/spec/type/map.rb,
lib/travis/yaml/spec/type/seq.rb,
lib/travis/yaml/doc/change/env.rb,
lib/travis/yaml/doc/change/key.rb,
lib/travis/yaml/doc/spec/fixed.rb,
lib/travis/yaml/doc/spec/types.rb,
lib/travis/yaml/doc/spec/value.rb,
lib/travis/yaml/doc/value/cast.rb,
lib/travis/yaml/doc/value/node.rb,
lib/travis/yaml/helper/memoize.rb,
lib/travis/yaml/helper/support.rb,
lib/travis/yaml/spec/def/cache.rb,
lib/travis/yaml/spec/def/group.rb,
lib/travis/yaml/spec/def/stack.rb,
lib/travis/yaml/spec/type/lang.rb,
lib/travis/yaml/spec/type/node.rb,
lib/travis/yaml/doc/change/base.rb,
lib/travis/yaml/doc/change/cast.rb,
lib/travis/yaml/doc/change/keys.rb,
lib/travis/yaml/doc/change/pick.rb,
lib/travis/yaml/doc/change/wrap.rb,
lib/travis/yaml/doc/helper/keys.rb,
lib/travis/yaml/doc/spec/lookup.rb,
lib/travis/yaml/doc/spec/scalar.rb,
lib/travis/yaml/spec/def/addons.rb,
lib/travis/yaml/spec/def/deploy.rb,
lib/travis/yaml/spec/def/lang/c.rb,
lib/travis/yaml/spec/def/lang/d.rb,
lib/travis/yaml/spec/def/lang/r.rb,
lib/travis/yaml/spec/def/matrix.rb,
lib/travis/yaml/spec/def/stages.rb,
lib/travis/yaml/spec/type/fixed.rb,
lib/travis/yaml/doc/change/cache.rb,
lib/travis/yaml/doc/change/merge.rb,
lib/travis/yaml/doc/change/value.rb,
lib/travis/yaml/doc/helper/match.rb,
lib/travis/yaml/doc/spec/mapping.rb,
lib/travis/yaml/doc/value/scalar.rb,
lib/travis/yaml/doc/value/secure.rb,
lib/travis/yaml/spec/def/deploys.rb,
lib/travis/yaml/spec/def/lang/go.rb,
lib/travis/yaml/spec/type/lookup.rb,
lib/travis/yaml/spec/type/scalar.rb,
lib/travis/yaml/doc/change/enable.rb,
lib/travis/yaml/doc/change/prefix.rb,
lib/travis/yaml/doc/change/repair.rb,
lib/travis/yaml/doc/helper/lookup.rb,
lib/travis/yaml/doc/value/support.rb,
lib/travis/yaml/spec/def/branches.rb,
lib/travis/yaml/spec/def/lang/cpp.rb,
lib/travis/yaml/spec/def/lang/nix.rb,
lib/travis/yaml/spec/def/lang/php.rb,
lib/travis/yaml/spec/def/language.rb,
lib/travis/yaml/spec/def/services.rb,
lib/travis/yaml/spec/type/mapping.rb,
lib/travis/yaml/doc/change/inherit.rb,
lib/travis/yaml/doc/change/migrate.rb,
lib/travis/yaml/doc/helper/support.rb,
lib/travis/yaml/doc/validate/alert.rb,
lib/travis/yaml/doc/validate/empty.rb,
lib/travis/yaml/doc/validate/flags.rb,
lib/travis/yaml/spec/def/addon/apt.rb,
lib/travis/yaml/spec/def/compilers.rb,
lib/travis/yaml/spec/def/deploy/s3.rb,
lib/travis/yaml/spec/def/lang/dart.rb,
lib/travis/yaml/spec/def/lang/haxe.rb,
lib/travis/yaml/spec/def/lang/java.rb,
lib/travis/yaml/spec/def/lang/perl.rb,
lib/travis/yaml/spec/def/lang/ruby.rb,
lib/travis/yaml/spec/def/lang/rust.rb,
lib/travis/yaml/spec/type/mappings.rb,
lib/travis/yaml/doc/change/downcase.rb,
lib/travis/yaml/doc/validate/format.rb,
lib/travis/yaml/spec/def/addon/jwts.rb,
lib/travis/yaml/spec/def/deploy/gae.rb,
lib/travis/yaml/spec/def/deploy/gcs.rb,
lib/travis/yaml/spec/def/deploy/npm.rb,
lib/travis/yaml/spec/def/lang/julia.rb,
lib/travis/yaml/spec/def/lang/perl6.rb,
lib/travis/yaml/spec/def/lang/scala.rb,
lib/travis/yaml/spec/def/lang/shell.rb,
lib/travis/yaml/doc/validate/default.rb,
lib/travis/yaml/doc/validate/version.rb,
lib/travis/yaml/spec/def/deploy/deis.rb,
lib/travis/yaml/spec/def/deploy/pypi.rb,
lib/travis/yaml/spec/def/lang/csharp.rb,
lib/travis/yaml/spec/def/lang/elixir.rb,
lib/travis/yaml/spec/def/lang/erlang.rb,
lib/travis/yaml/spec/def/lang/groovy.rb,
lib/travis/yaml/spec/def/lang/python.rb,
lib/travis/yaml/spec/type/conditions.rb,
lib/travis/yaml/doc/validate/required.rb,
lib/travis/yaml/doc/validate/template.rb,
lib/travis/yaml/spec/def/deploy/atlas.rb,
lib/travis/yaml/spec/def/deploy/pages.rb,
lib/travis/yaml/spec/def/deploy/surge.rb,
lib/travis/yaml/spec/def/lang/android.rb,
lib/travis/yaml/spec/def/lang/clojure.rb,
lib/travis/yaml/spec/def/lang/crystal.rb,
lib/travis/yaml/spec/def/lang/haskell.rb,
lib/travis/yaml/spec/def/lang/node_js.rb,
lib/travis/yaml/doc/validate/condition.rb,
lib/travis/yaml/doc/validate/validator.rb,
lib/travis/yaml/spec/def/deploy/appfog.rb,
lib/travis/yaml/spec/def/deploy/heroku.rb,
lib/travis/yaml/spec/def/deploy/lambda.rb,
lib/travis/yaml/spec/def/deploy/script.rb,
lib/travis/yaml/spec/def/notifications.rb,
lib/travis/yaml/spec/def/deploy/bintray.rb,
lib/travis/yaml/spec/def/deploy/boxfuse.rb,
lib/travis/yaml/spec/def/deploy/cloud66.rb,
lib/travis/yaml/spec/def/deploy/divshot.rb,
lib/travis/yaml/spec/def/deploy/hackage.rb,
lib/travis/yaml/spec/def/deploy/modulus.rb,
lib/travis/yaml/spec/def/lang/smalltalk.rb,
lib/travis/yaml/spec/def/addon/artifacts.rb,
lib/travis/yaml/spec/def/deploy/anynines.rb,
lib/travis/yaml/spec/def/deploy/catalyze.rb,
lib/travis/yaml/spec/def/deploy/firebase.rb,
lib/travis/yaml/spec/def/deploy/opsworks.rb,
lib/travis/yaml/spec/def/deploy/releases.rb,
lib/travis/yaml/spec/def/deploy/rubygems.rb,
lib/travis/yaml/spec/def/deploy/scalingo.rb,
lib/travis/yaml/doc/validate/invalid_type.rb,
lib/travis/yaml/doc/validate/unknown_keys.rb,
lib/travis/yaml/spec/def/deploy/launchpad.rb,
lib/travis/yaml/spec/def/deploy/openshift.rb,
lib/travis/yaml/spec/def/deploy/testfairy.rb,
lib/travis/yaml/spec/def/lang/objective_c.rb,
lib/travis/yaml/spec/def/notification/irc.rb,
lib/travis/yaml/doc/validate/unknown_value.rb,
lib/travis/yaml/spec/def/deploy/bitballoon.rb,
lib/travis/yaml/spec/def/deploy/cloudfiles.rb,
lib/travis/yaml/spec/def/deploy/codedeploy.rb,
lib/travis/yaml/spec/def/deploy/engineyard.rb,
lib/travis/yaml/spec/def/addon/browserstack.rb,
lib/travis/yaml/spec/def/addon/code_climate.rb,
lib/travis/yaml/spec/def/deploy/puppetforge.rb,
lib/travis/yaml/spec/def/lang/worker_stacks.rb,
lib/travis/yaml/spec/def/notification/email.rb,
lib/travis/yaml/spec/def/notification/slack.rb,
lib/travis/yaml/doc/validate/unsupported_key.rb,
lib/travis/yaml/spec/def/addon/coverity_scan.rb,
lib/travis/yaml/spec/def/addon/sauce_connect.rb,
lib/travis/yaml/spec/def/deploy/cloudcontrol.rb,
lib/travis/yaml/spec/def/deploy/cloudfoundry.rb,
lib/travis/yaml/spec/def/deploy/packagecloud.rb,
lib/travis/yaml/spec/def/notification/hipchat.rb,
lib/travis/yaml/doc/validate/unsupported_value.rb,
lib/travis/yaml/spec/def/deploy/azure_web_apps.rb,
lib/travis/yaml/spec/def/notification/campfire.rb,
lib/travis/yaml/spec/def/notification/flowdock.rb,
lib/travis/yaml/spec/def/notification/pushover.rb,
lib/travis/yaml/spec/def/notification/webhooks.rb,
lib/travis/yaml/spec/def/deploy/chef_supermarket.rb,
lib/travis/yaml/spec/def/deploy/elasticbeanstalk.rb,
lib/travis/yaml/spec/def/deploy/bluemix_cloudfoundry.rb

Defined Under Namespace

Modules: Doc, Helper, Spec, Web Classes: Error, Expand, InputError, InternalError, InvalidCondition, Match, Matrix, MemoizedArgs, StackTooHigh, Support, UnexpectedConfigFormat, UnexpectedParentType, UnexpectedValue, UnknownMessage

Constant Summary collapse

DEFAULTS =
{
  language: 'ruby',
  os:       'linux'
}
MSGS =

these are meant as examples. we might want to determine the translation in the client

{
  alert:           'using a plain string as a secure',
  alias:           '%{alias} is an alias for %{actual}, using %{actual}',
  cast:            'casting value %{given_value} (%{given_type}) to %{value} (%{type})',
  default:         'missing %{key}, defaulting to: %{default}',
  deprecated:      '%{given} is deprecated',
  downcase:        'downcasing %{value}',
  edge:            '%{given} is experimental and might be removed in the future',
  flagged:         'your repository must be feature flagged for %{given} to be used',
  irrelevant:      'specified %{key}, but this setting is not relevant for the %{on_key} %{on_value}',
  unsupported:     '%{key} (%{value}) is not supported on the %{on_key} %{on_value}',
  required:        'missing required key %{key}',
  empty:           'dropping empty section %{key}',
  find_key:        'key %{original} is not known, but %{key} is, using %{key}',
  find_value:      'value %{original} is not known, but %{value} is, using %{value}',
  clean_key:       'key %{original} contains special characters, using %{key}',
  clean_value:     'value %{original} is not known, but %{value} is, using %{value}',
  underscore_key:  'key %{original} is camelcased, using %{key}',
  migrate:         'migrating %{key} to %{to} (value: %{value})',
  misplaced_key:   'dropping misplaced key %{key} (%{value})',
  unknown_key:     'dropping unknown key %{key} (%{value})',
  unknown_value:   'dropping unknown value: %{value}',
  unknown_default: 'dropping unknown value: %{value}, defaulting to: %{default}',
  unknown_var:     'unknown template variable %{var}',
  invalid_key:     '%{key} is not a valid key',
  invalid_type:    'dropping unexpected %{actual}, expected %{expected} (%{value})',
  invalid_format:  'dropping invalid format: %{value}',
  invalid_seq:     'unexpected sequence, using the first value (%{value})'
  # invalid_value:   '%{value} is not a valid value on this key',
}
VERSION =
'0.0.1'

Constants included from Helper::Deyaml

Helper::Deyaml::DROP

Class Method Summary collapse

Methods included from Helper::Deyaml

deyaml, deyaml_key, drop_keys

Class Method Details

.apply(input, opts = {}) ⇒ Object


71
72
73
74
75
76
77
78
# File 'lib/travis/yaml.rb', line 71

def apply(input, opts = {})
  raise UnexpectedConfigFormat, 'Input must be a hash' unless input.is_a?(Hash)
  input = deyaml(input)
  node = build(input, opts)
  node = Doc::Change.apply(expanded, node)
  node = Doc::Validate.apply(expanded, node)
  node
end

.build(input, opts = {}) ⇒ Object


80
81
82
# File 'lib/travis/yaml.rb', line 80

def build(input, opts = {})
  Doc::Value.build(nil, :root, input, opts)
end

.expandedObject


63
64
65
# File 'lib/travis/yaml.rb', line 63

def expanded
  @expanded ||= Doc::Spec::Map.new(nil, Expand.new(spec).apply)
end

.keysObject


92
93
94
# File 'lib/travis/yaml.rb', line 92

def keys
  @keys ||= expanded.all_keys
end

.load(yaml, opts = {}) ⇒ Object


58
59
60
61
# File 'lib/travis/yaml.rb', line 58

def load(yaml, opts = {})
  hash = YAML.load(yaml.strip, raise_on_unknown_tag: true) || {}
  apply(hash, opts)
end

.matrix(config) ⇒ Object


84
85
86
# File 'lib/travis/yaml.rb', line 84

def matrix(config)
  Matrix.new(spec, config)
end

.msg(msg) ⇒ Object


107
108
109
110
111
112
113
# File 'lib/travis/yaml.rb', line 107

def msg(msg)
  level, key, code, args = msg
  msg = MSGS[code] || raise(UnknownMessage, 'Unknown message %p' % code)
  msg = msg % args.map { |key, value| [key, value.is_a?(Symbol) ? value.inspect : value] }.to_h if args
  msg = '[%s] on %s: %s' % [level, key, msg]
  msg
end

.r_keysObject


96
97
98
# File 'lib/travis/yaml.rb', line 96

def r_keys
  @r_keys ||= r_nodes.keys
end

.r_nodesObject

TODO R known keys on root should definitely be reduced


101
102
103
104
105
# File 'lib/travis/yaml.rb', line 101

def r_nodes
  support[:map].select do |key, node|
    node[:types].any? { |type| type.fetch(:only, {})[:language] == ['r'] }
  end
end

.specObject


67
68
69
# File 'lib/travis/yaml.rb', line 67

def spec
  @spec ||= Spec::Def::Root.new.spec
end

.supportObject


88
89
90
# File 'lib/travis/yaml.rb', line 88

def support
  spec[:includes][:support]
end