Sha256: 55cf68aea2abcc2a95875b2813c6064fda50329107d4c601ee8fbdc4d6361452

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

module Shipit
  class TaskDefinition
    NotFound = Class.new(StandardError)

    class << self
      def load(payload)
        return unless payload.present?
        json = JSON.parse(payload)
        new(json.delete('id'), json)
      end

      def dump(definition)
        return unless definition.present?
        JSON.dump(definition.as_json)
      end
    end

    attr_reader :id, :action, :description, :steps, :checklist, :variables
    alias_method :to_param, :id

    def initialize(id, config)
      @id = id
      @action = config['action']
      @description = config['description'] || ''
      @steps = config['steps'] || []
      @variables = task_variables(config['variables'] || [])
      @checklist = config['checklist'] || []
      @allow_concurrency = config['allow_concurrency'] || false
    end

    def allow_concurrency?
      @allow_concurrency
    end

    def as_json
      {
        id: id,
        action: action,
        description: description,
        steps: steps,
        variables: variables.map(&:to_h),
        checklist: checklist,
        allow_concurrency: allow_concurrency?,
      }
    end

    def filter_envs(env)
      EnvironmentVariables.with(env).permit(variables)
    end

    def variables_with_defaults
      @variables_with_defaults ||= variables.select(&:default_provided?)
    end

    private

    def task_variables(config_variables)
      config_variables.map(&VariableDefinition.method(:new))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shipit-engine-0.20.1 app/models/shipit/task_definition.rb
shipit-engine-0.20.0 app/models/shipit/task_definition.rb
shipit-engine-0.19.0 app/models/shipit/task_definition.rb
shipit-engine-0.18.1 app/models/shipit/task_definition.rb
shipit-engine-0.18.0 app/models/shipit/task_definition.rb
shipit-engine-0.17.0 app/models/shipit/task_definition.rb