Skip to content

Commit

Permalink
namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed May 22, 2019
1 parent 66a69de commit 9fec86e
Show file tree
Hide file tree
Showing 131 changed files with 1,170 additions and 3,700 deletions.
6 changes: 3 additions & 3 deletions lib/travis/yml/doc/change/keys.rb
Expand Up @@ -16,13 +16,13 @@ def apply
private

def change(value)
value = defaults(value) if defaults?
value = required(value) if defaults?
value = fix_keys(value)
value
end

def defaults(node)
keys = schema.defaults + value.keys
def required(node)
keys = schema.required + value.keys
build(keys.uniq.map { |key| [key, value[key] || none] }.to_h)
end

Expand Down
12 changes: 7 additions & 5 deletions lib/travis/yml/doc/validate/default.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
# require 'travis/yml/doc/helper/support'
require 'travis/yml/doc/value/factory'
require 'travis/yml/doc/validate/base'

Expand All @@ -9,7 +8,6 @@ module Doc
module Validate
class Default < Base
include Value::Factory
# include Helper::Support

register :default

Expand All @@ -24,15 +22,15 @@ def apply?
end

def default?
schema.default? && value.missing? && supported?
schema.default? && value.missing? # && supported?
end

def invalid_type?
value.errored? && value.type != schema.type
end

def default
default = supported.value
default = supported&.value || defaults.first.value
value.info :default, default: default
build(value.parent, value.key, schema.seq? ? [default] : default, value.opts)
end
Expand All @@ -47,10 +45,14 @@ def supported
memoize :supported

def support(value)
support = schema.defaults.support(value.value)
support = defaults.support(value.value)
Value::Support.new(support, supporting, value.value)
end

def defaults
schema.defaults
end

def supporting
value.supporting
end
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/yml/doc/validate/required.rb
Expand Up @@ -39,7 +39,7 @@ def keys
end

def enabled?
value.enabled?(:required)
value.enabled?(:defaults)
end
end
end
Expand Down
11 changes: 4 additions & 7 deletions lib/travis/yml/doc/value/node.rb
Expand Up @@ -135,15 +135,12 @@ def msgs
opts[:msgs] ||= []
end

def full_key
keys = ancestors.map(&:key).uniq.compact
keys = [:root] if keys.empty?
keys.join('.').to_sym
def full_key(ext = true)
root? ? :root : full_keys.join('.').to_sym
end

def ancestors
ancestors = parent.respond_to?(:ancestors) ? parent.ancestors : []
ancestors + [self]
def full_keys
root? ? [] : [*parent.full_keys, key].uniq
end

def walk(level = 0)
Expand Down
4 changes: 4 additions & 0 deletions lib/travis/yml/doc/value/seq.rb
Expand Up @@ -16,6 +16,10 @@ def first
value.first
end

def index(node)
value.index(node)
end

def each(&block)
value.each(&block) && self
end
Expand Down
4 changes: 2 additions & 2 deletions lib/travis/yml/docs.rb
Expand Up @@ -104,7 +104,7 @@ def path(name)
def pages
nodes.map do |node|
[[node.namespace, node.id].join('/'), Page.new(node).render]
end
end.to_h
end

def index
Expand All @@ -115,7 +115,7 @@ def index

def nodes
Schema.schema
nodes = Schema::Type::Node.exports.values
nodes = Schema::Type::Node.exports.values.map(&:values).flatten
nodes = nodes.reject(&:internal?)
# nodes = [Schema::Def::Stages.new.node.lookup]
nodes = sort(nodes)
Expand Down
3 changes: 2 additions & 1 deletion lib/travis/yml/schema/def/addons.rb
Expand Up @@ -7,6 +7,8 @@ module Schema
module Def
module Addon
class Addon < Dsl::Map
registry :addons

def define
namespace :addon
normal
Expand All @@ -17,7 +19,6 @@ def define
end

class Addons < Dsl::Map
registry :addons
register :addons

def define
Expand Down
31 changes: 18 additions & 13 deletions lib/travis/yml/schema/def/deploy.rb
Expand Up @@ -9,7 +9,9 @@ module Schema
module Def
module Deploy
def self.provider_names
Deploy.registry.values.map(&:registry_key).sort.compact
consts = Deploy.registry.values
consts = consts.select { |const| const < Deploy }
consts.map(&:registry_key).sort.compact
end

class Deploys < Dsl::Seq
Expand All @@ -23,7 +25,8 @@ def define
end

class Providers < Dsl::Any
register :deploy_providers
registry :deploy
register :providers

def define
normal
Expand All @@ -37,17 +40,16 @@ class Deploy < Dsl::Map
registry :deploy

def define
namespace :deploy
normal

strict false
prefix :provider

map :provider, to: :enum, values: registry_key, required: true, strict: true
map :on, to: :deploy_conditions
map :on, to: :conditions
map :allow_failure, to: :bool
map :skip_cleanup, to: :bool
map :edge, to: :deploy_edge
map :edge, to: :edge

# so called option specific branch hashes are valid, but
# deprecated according to travis-build. e.g.:
Expand All @@ -57,13 +59,12 @@ def define
# develop: foo
# production: bar

# map :'.*', to: :deploy_branches

# export
# map :'.*', to: :branches
end
end

class App < Dsl::Any
registry :deploy
register :app

def define
Expand All @@ -81,15 +82,16 @@ def define
end

class Conditions < Dsl::Map
register :deploy_conditions
registry :deploy
register :conditions

def define
include :languages

normal
prefix :branch

map :branch, to: :deploy_branches, alias: :branches
map :branch, to: :branches, alias: :branches
map :repo, to: :str
map :condition, to: :str
map :all_branches, to: :bool
Expand All @@ -100,7 +102,8 @@ def define
end

class Branches < Dsl::Any
register :deploy_branches
registry :deploy
register :branches

def define
add :seq, normal: true #, prefix: :branch
Expand All @@ -110,7 +113,8 @@ def define
end

class Branch < Dsl::Map
register :deploy_branch
registry :deploy
register :branch

def define
normal
Expand All @@ -121,7 +125,8 @@ def define
end

class Edge < Dsl::Map
register :deploy_edge
registry :deploy
register :edge

def define
edge
Expand Down
4 changes: 2 additions & 2 deletions lib/travis/yml/schema/def/job.rb
Expand Up @@ -16,8 +16,6 @@ class Job < Dsl::Map
register :job

def define
include :languages

strict false

map :group
Expand Down Expand Up @@ -46,6 +44,8 @@ def define
map :after_deploy, to: :seq
map :before_cache, to: :seq

include :languages

export
end
end
Expand Down
10 changes: 3 additions & 7 deletions lib/travis/yml/schema/def/language.rb
Expand Up @@ -24,13 +24,7 @@ def before_define
namespace :language
normal
strict false

# This sucks because now the :language key is known on deploy
# conditions (which need language specific keys). On the other
# hand, not having this key here would mean that on the JSON Schema
# level language specific keys would be valid on any language, not
# just the language that defines them.
map :language, values: registry_key
super
end

def after_define
Expand All @@ -46,6 +40,8 @@ def define

default :ruby, only: { os: [:linux, :windows] }
default :'objective-c', only: { os: [:osx] }

# enum values will be registered from Dsl::Lang
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/travis/yml/schema/def/matrix.rb
Expand Up @@ -34,8 +34,6 @@ class Entry < Dsl::Map
register :matrix_entry

def define
include :job

strict false
aliases :jobs

Expand All @@ -49,6 +47,8 @@ def define
map :stage
map :compiler, to: :compilers

include :job

export
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/travis/yml/schema/def/root.rb
Expand Up @@ -26,14 +26,12 @@ class Root < Dsl::Schema
def define
title 'JSON schema for Travis CI configuration files'

include :job

strict false

map :version
map :import, to: :imports
map :language
matrix :os, to: :oss
map :language, required: true
matrix :os, required: true, to: :oss
matrix :arch, to: :archs
map :dist
map :sudo
Expand All @@ -46,6 +44,8 @@ def define
map :conditions, to: :conditions #, default: :v1
map :filter_secrets, to: :bool
map :trace, to: :bool

include :job
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/travis/yml/schema/dsl/enum.rb
Expand Up @@ -31,7 +31,9 @@ def strict(obj = true)
def values(*objs)
objs = objs.flatten.compact

if objs.first.is_a?(Hash)
if objs.empty?
return
elsif objs.first.is_a?(Hash)
node.set(:enum, to_enum(objs))
node.set(:values, merge(compact(to_vals(remap(objs)))))
else
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/yml/schema/dsl/group.rb
Expand Up @@ -8,7 +8,7 @@ module Dsl
class Group < Node
def add(*types)
opts = types.last.is_a?(Hash) ? types.pop : {}
schemas = types.map { |type| Node.build(self, type, opts).node }
schemas = types.map { |type| build(self, type, opts).node }
node.schemas.concat(schemas)
end
end
Expand Down
11 changes: 10 additions & 1 deletion lib/travis/yml/schema/dsl/lang.rb
Expand Up @@ -12,6 +12,11 @@ def self.type
:lang
end

def before_define
language.set(:enum, [registry_key])
language.set(:values, registry_key => {})
end

def aliases(*aliases)
language.set(:values, registry_key => { aliases: to_strs(aliases) })
end
Expand All @@ -20,6 +25,10 @@ def deprecated(obj)
language.set(:values, registry_key => { deprecated: obj })
end

# def supports(support)
# language.set(:values, registry_key => support)
# end

def matrix(key, opts = {})
opts = opts.merge(only: { language: registry_key })
opts[:to] ||= :seq
Expand All @@ -32,7 +41,7 @@ def map(key, opts = {})
end

def language
node.mappings[:language]
root.node.mappings[:language]
end
end
end
Expand Down

0 comments on commit 9fec86e

Please sign in to comment.