class Perkins::Build::Data

Constants

DEFAULTS
DEFAULT_CACHES

Attributes

data[R]

Public Class Methods

new(data, defaults = {}) click to toggle source
# File lib/perkins/build/data.rb, line 24
def initialize(data, defaults = {})
  data = data.deep_symbolize_keys
  defaults = defaults.deep_symbolize_keys
  @data = DEFAULTS.deep_merge(defaults.deep_merge(data))
end

Public Instance Methods

api_url() click to toggle source
# File lib/perkins/build/data.rb, line 126
def api_url
  repository[:api_url]
end
branch() click to toggle source
# File lib/perkins/build/data.rb, line 142
def branch
  job[:branch]
end
build() click to toggle source
# File lib/perkins/build/data.rb, line 154
def build
  data[:source] || data[:build] || {} # TODO standarize the payload on :build
end
cache(input = config[:cache]) click to toggle source
# File lib/perkins/build/data.rb, line 58
def cache(input = config[:cache])
  case input
  when Hash           then input
  when Array          then input.map { |e| cache(e) }.inject(:merge)
  when String, Symbol then { input.to_sym => true }
  when nil            then {} # for ruby 1.9
  when false          then Hash[DEFAULT_CACHES.each_key.with_object(false).to_a]
  else input.to_h
  end
end
cache?(type, default = DEFAULT_CACHES[type]) click to toggle source
# File lib/perkins/build/data.rb, line 69
def cache?(type, default = DEFAULT_CACHES[type])
  type &&= type.to_sym
  !!cache.fetch(type) { default }
end
cache_options() click to toggle source
# File lib/perkins/build/data.rb, line 54
def cache_options
  data[:cache_options] || {}
end
commit() click to toggle source
# File lib/perkins/build/data.rb, line 138
def commit
  job[:commit]
end
config() click to toggle source
# File lib/perkins/build/data.rb, line 34
def config
  data[:config]
end
env_vars() click to toggle source
# File lib/perkins/build/data.rb, line 74
def env_vars
  @env_vars ||= Env.new(self).vars
end
env_vars_groups() click to toggle source
# File lib/perkins/build/data.rb, line 78
def env_vars_groups
  @env_vars_groups ||= Env.new(self).vars_groups
end
hosts() click to toggle source
# File lib/perkins/build/data.rb, line 38
def hosts
  data[:hosts] || {}
end
job() click to toggle source
# File lib/perkins/build/data.rb, line 150
def job
  data[:job] || {}
end
paranoid_mode?() click to toggle source
# File lib/perkins/build/data.rb, line 42
def paranoid_mode?
  data.fetch(:paranoid, false)
end
pull_request() click to toggle source
# File lib/perkins/build/data.rb, line 114
def pull_request
  job[:pull_request]
end
raw_env_vars() click to toggle source
# File lib/perkins/build/data.rb, line 82
def raw_env_vars
  data[:env_vars] || []
end
ref() click to toggle source
# File lib/perkins/build/data.rb, line 146
def ref
  job[:ref]
end
repository() click to toggle source
# File lib/perkins/build/data.rb, line 158
def repository
  data[:repository] || {}
end
secure_env_enabled?() click to toggle source
# File lib/perkins/build/data.rb, line 118
def secure_env_enabled?
  job[:secure_env_enabled]
end
skip_etc_hosts_fix?() click to toggle source
# File lib/perkins/build/data.rb, line 50
def skip_etc_hosts_fix?
  data.fetch(:skip_etc_hosts_fix, false)
end
skip_resolv_updates?() click to toggle source
# File lib/perkins/build/data.rb, line 46
def skip_resolv_updates?
  data.fetch(:skip_resolv_updates, false)
end
slug() click to toggle source
# File lib/perkins/build/data.rb, line 134
def slug
  repository[:slug]
end
source_host() click to toggle source
# File lib/perkins/build/data.rb, line 122
def source_host
  source_url =~ %r(^(?:https?|git)(?:://|@)([^/]*?)(?:/|:)) && $1
end
source_url() click to toggle source
# File lib/perkins/build/data.rb, line 130
def source_url
  repository[:source_url]
end
ssh_key() click to toggle source
# File lib/perkins/build/data.rb, line 106
def ssh_key
  if ssh_key = data[:ssh_key]
    SshKey.new(ssh_key[:value], ssh_key[:source], ssh_key[:encoded])
  elsif source_key = data[:config][:source_key]
    SshKey.new(source_key, nil, true)
  end
end
token() click to toggle source
# File lib/perkins/build/data.rb, line 162
def token
  data[:oauth_token]
end
urls() click to toggle source
# File lib/perkins/build/data.rb, line 30
def urls
  data[:urls] || {}
end