Class: Perkins::Build::Data

Inherits:
Object show all
Defined in:
lib/perkins/build/data.rb,
lib/perkins/build/data/env.rb,
lib/perkins/build/data/var.rb

Defined Under Namespace

Classes: Env, SshKey, Var

Constant Summary collapse

DEFAULTS =
{ }
DEFAULT_CACHES =
{
  apt:       false,
  bundler:   false,
  cocoapods: false,
  composer:  false
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, defaults = {}) ⇒ Data

Returns a new instance of Data.



24
25
26
27
28
# 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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/perkins/build/data.rb', line 22

def data
  @data
end

Instance Method Details

#api_urlObject



126
127
128
# File 'lib/perkins/build/data.rb', line 126

def api_url
  repository[:api_url]
end

#branchObject



142
143
144
# File 'lib/perkins/build/data.rb', line 142

def branch
  job[:branch]
end

#buildObject



154
155
156
# 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]) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# 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]) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
# 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_optionsObject



54
55
56
# File 'lib/perkins/build/data.rb', line 54

def cache_options
  data[:cache_options] || {}
end

#commitObject



138
139
140
# File 'lib/perkins/build/data.rb', line 138

def commit
  job[:commit]
end

#configObject



34
35
36
# File 'lib/perkins/build/data.rb', line 34

def config
  data[:config]
end

#env_varsObject



74
75
76
# File 'lib/perkins/build/data.rb', line 74

def env_vars
  @env_vars ||= Env.new(self).vars
end

#env_vars_groupsObject



78
79
80
# File 'lib/perkins/build/data.rb', line 78

def env_vars_groups
  @env_vars_groups ||= Env.new(self).vars_groups
end

#hostsObject



38
39
40
# File 'lib/perkins/build/data.rb', line 38

def hosts
  data[:hosts] || {}
end

#jobObject



150
151
152
# File 'lib/perkins/build/data.rb', line 150

def job
  data[:job] || {}
end

#paranoid_mode?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/perkins/build/data.rb', line 42

def paranoid_mode?
  data.fetch(:paranoid, false)
end

#pull_requestObject



114
115
116
# File 'lib/perkins/build/data.rb', line 114

def pull_request
  job[:pull_request]
end

#raw_env_varsObject



82
83
84
# File 'lib/perkins/build/data.rb', line 82

def raw_env_vars
  data[:env_vars] || []
end

#refObject



146
147
148
# File 'lib/perkins/build/data.rb', line 146

def ref
  job[:ref]
end

#repositoryObject



158
159
160
# File 'lib/perkins/build/data.rb', line 158

def repository
  data[:repository] || {}
end

#secure_env_enabled?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/perkins/build/data.rb', line 118

def secure_env_enabled?
  job[:secure_env_enabled]
end

#skip_etc_hosts_fix?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/perkins/build/data.rb', line 50

def skip_etc_hosts_fix?
  data.fetch(:skip_etc_hosts_fix, false)
end

#skip_resolv_updates?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/perkins/build/data.rb', line 46

def skip_resolv_updates?
  data.fetch(:skip_resolv_updates, false)
end

#slugObject



134
135
136
# File 'lib/perkins/build/data.rb', line 134

def slug
  repository[:slug]
end

#source_hostObject



122
123
124
# File 'lib/perkins/build/data.rb', line 122

def source_host
  source_url =~ %r(^(?:https?|git)(?:://|@)([^/]*?)(?:/|:)) && $1
end

#source_urlObject



130
131
132
# File 'lib/perkins/build/data.rb', line 130

def source_url
  repository[:source_url]
end

#ssh_keyObject



106
107
108
109
110
111
112
# 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

#tokenObject



162
163
164
# File 'lib/perkins/build/data.rb', line 162

def token
  data[:oauth_token]
end

#urlsObject



30
31
32
# File 'lib/perkins/build/data.rb', line 30

def urls
  data[:urls] || {}
end