Sha256: 7c78128150b8e201ac8ccb5cffa91dea26c17744b9c4143d8997e512a0ac4678

Contents?: true

Size: 1.33 KB

Versions: 19

Compression:

Stored size: 1.33 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

    private

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
shipit-engine-0.16.0 app/models/shipit/task_definition.rb
shipit-engine-0.15.0 app/models/shipit/task_definition.rb
shipit-engine-0.14.0 app/models/shipit/task_definition.rb
shipit-engine-0.13.0 app/models/shipit/task_definition.rb
shipit-engine-0.12.1 app/models/shipit/task_definition.rb
shipit-engine-0.12.0 app/models/shipit/task_definition.rb
shipit-engine-0.11.0 app/models/shipit/task_definition.rb
shipit-engine-0.10.0 app/models/shipit/task_definition.rb
shipit-engine-0.9.0 app/models/shipit/task_definition.rb
shipit-engine-0.8.9 app/models/shipit/task_definition.rb
shipit-engine-0.8.8 app/models/shipit/task_definition.rb
shipit-engine-0.8.7 app/models/shipit/task_definition.rb
shipit-engine-0.8.6 app/models/shipit/task_definition.rb
shipit-engine-0.8.5 app/models/shipit/task_definition.rb
shipit-engine-0.8.4 app/models/shipit/task_definition.rb
shipit-engine-0.8.3 app/models/shipit/task_definition.rb
shipit-engine-0.8.2 app/models/shipit/task_definition.rb
shipit-engine-0.8.1 app/models/shipit/task_definition.rb
shipit-engine-0.8.0 app/models/shipit/task_definition.rb