module Buildkite::Pipelines::Attributes

Public Class Methods

included(base) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 8
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

append(attr, value) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 29
def append(attr, value)
  ensure_array_value(attr)
  get(attr).push(*[value].flatten)
  value
end
get(attr) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 12
def get(attr)
  attributes[validate(attr)]
end
has?(attr) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 20
def has?(attr)
  # Don't validate for has? calls.
  attributes.key?(attr.to_s)
end
permits?(attr) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 25
def permits?(attr)
  self.class.permits?(attr)
end
permitted_attributes() click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 41
def permitted_attributes
  self.class.permitted_attributes
end
prepend(attr, value) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 35
def prepend(attr, value)
  ensure_array_value(attr)
  get(attr).unshift(*[value].flatten)
  value
end
set(attr, value) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 16
def set(attr, value)
  attributes[validate(attr)] = value
end
to_h() click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 49
def to_h
  permitted_attributes.each_with_object({}) do |attr, hash|
    next unless has?(attr)

    hash[attr] = get(attr).respond_to?(:to_definition) ? get(attr).to_definition : get(attr)
  end
end
unset(attr) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 45
def unset(attr)
  attributes.delete(validate(attr))
end

Private Instance Methods

attributes() click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 117
def attributes
  @attributes ||= {}
end
ensure_array_value(attr) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 121
def ensure_array_value(attr)
  if has?(attr)
    set(attr, [get(attr)]) unless get(attr).is_a?(Array)
  else
    set(attr, [])
  end
end
validate(attr) click to toggle source
# File lib/buildkite/pipelines/attributes.rb, line 129
def validate(attr)
  attr = attr.to_s
  unless permits?(attr)
    raise "Attribute not permitted on #{self.class.name} step: #{attr}"
  end

  attr
end