Sha256: 1c4a8a95a44e622453d8121647e06b9fe344b9f02ced22f5fff0d584c843d754

Contents?: true

Size: 1.41 KB

Versions: 13

Compression:

Stored size: 1.41 KB

Contents

require 'active_model'

module Avrolution
  class CompatibilityBreak
    include ActiveModel::Validations

    ValidationError = Class.new(StandardError)

    VALID_COMPATIBILITY_VALUES = %w(BACKWARD BACKWARD_TRANSITIVE FORWARD
                                    FORWARD_TRANSITIVE FULL FULL_TRANSITIVE NONE).map(&:freeze).freeze
    NONE = 'NONE'.freeze

    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

13 entries across 13 versions & 1 rubygems

Version Path
avrolution-0.6.1 lib/avrolution/compatibility_break.rb
avrolution-0.6.0 lib/avrolution/compatibility_break.rb
avrolution-0.5.0 lib/avrolution/compatibility_break.rb
avrolution-0.5.0.rc0 lib/avrolution/compatibility_break.rb
avrolution-0.4.4 lib/avrolution/compatibility_break.rb
avrolution-0.4.3 lib/avrolution/compatibility_break.rb
avrolution-0.4.2 lib/avrolution/compatibility_break.rb
avrolution-0.4.1 lib/avrolution/compatibility_break.rb
avrolution-0.4.1.rc0 lib/avrolution/compatibility_break.rb
avrolution-0.4.0 lib/avrolution/compatibility_break.rb
avrolution-0.4.0.rc1 lib/avrolution/compatibility_break.rb
avrolution-0.4.0.rc0 lib/avrolution/compatibility_break.rb
avrolution-0.3.0 lib/avrolution/compatibility_break.rb