Class: Pipely::Deploy::JSONDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/pipely/deploy/json_definition.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ JSONDefinition

Returns a new instance of JSONDefinition.



16
17
18
19
20
# File 'lib/pipely/deploy/json_definition.rb', line 16

def initialize(object)
  @json_fields = object.clone
  @id = @json_fields.delete('id')
  @name = @json_fields.delete('name') || @id
end

Class Method Details

.parse(definition) ⇒ Object



11
12
13
14
# File 'lib/pipely/deploy/json_definition.rb', line 11

def self.parse(definition)
  definition_objects = JSON.parse(definition)['objects']
  definition_objects.map { |object| new(object).to_api }
end

Instance Method Details

#to_apiObject



22
23
24
25
26
27
28
# File 'lib/pipely/deploy/json_definition.rb', line 22

def to_api
  {
    'id' => @id,
    'name' => @name,
    'fields' => fields
  }
end