class Pipely::Deploy::JSONDefinition

The JSON definition format expected by the CLI differs from the structure expected by the API. This class transforms a CLI-ready definition into the pipeline object hashes expected by the API.

Public Class Methods

new(object) click to toggle source
# File lib/pipely/deploy/json_definition.rb, line 17
def initialize(object)
  @json_fields = object.clone
  @id = @json_fields.delete(:id)
  @name = @json_fields.delete(:name) || @id
end
parse(definition) click to toggle source
# File lib/pipely/deploy/json_definition.rb, line 11
def self.parse(definition)
  definition_objects =
    JSON.parse(definition, symbolize_names: true)[:objects]
  definition_objects.map { |object| new(object).to_api }
end

Public Instance Methods

to_api() click to toggle source
# File lib/pipely/deploy/json_definition.rb, line 23
def to_api
  {
    id: @id,
    name: @name,
    fields: fields
  }
end

Private Instance Methods

field_for_kv(key, value) click to toggle source
# File lib/pipely/deploy/json_definition.rb, line 37
def field_for_kv(key, value)
  if value.is_a?(Hash)
    { key: key, ref_value: value[:ref] }

  elsif value.is_a?(Array)
    value.map { |subvalue| field_for_kv(key, subvalue) }

  else
    { key: key, string_value: value }

  end
end
fields() click to toggle source
# File lib/pipely/deploy/json_definition.rb, line 33
def fields
  @json_fields.map{|k,v| field_for_kv(k,v)}.flatten
end