Sha256: 095cf79ab93d363f2015a48983f8c6cb66efb8f4cbc05096084a766744b74f14

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'active_model'

module Avrolution
  class CompatibilityBreak
    include ActiveModel::Validations

    ValidationError = Class.new(StandardError)

    VALID_COMPATIBILITY_VALUES = [
      'BACKWARD',
      'BACKWARD_TRANSITIVE',
      'FORWARD',
      'FORWARD_TRANSITIVE',
      'FULL',
      'FULL_TRANSITIVE',
      'NONE'
    ].freeze
    NONE = 'NONE'

    attr_reader :name, :fingerprint, :with_compatibility, :after_compatibility

    validates_presence_of :name, :fingerprint
    validates_inclusion_of :with_compatibility, in: VALID_COMPATIBILITY_VALUES, allow_nil: true
    validates_inclusion_of :after_compatibility, in: VALID_COMPATIBILITY_VALUES, allow_nil: true

    def initialize(name, fingerprint, with_compatibility = NONE, after_compatibility = nil, *extra)
      @name = name
      @fingerprint = fingerprint
      @with_compatibility = with_compatibility.upcase
      @after_compatibility = after_compatibility.try(:upcase)
      @extra = extra
    end

    def key
      [name, fingerprint]
    end

    def validate!
      raise ValidationError.new(errors.full_messages.join(', ')) unless valid?
    end

    def line
      [name, fingerprint, with_compatibility, after_compatibility].compact.join(' ')
    end

    def register_options
      { with_compatibility: with_compatibility }.tap do |options|
        options[:after_compatibility] = after_compatibility if after_compatibility.present?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
avrolution-0.9.0 lib/avrolution/compatibility_break.rb
avrolution-0.8.0 lib/avrolution/compatibility_break.rb
avrolution-0.7.2 lib/avrolution/compatibility_break.rb
avrolution-0.7.1 lib/avrolution/compatibility_break.rb
avrolution-0.7.0 lib/avrolution/compatibility_break.rb