<commit_before>module RubyEventStore
  class ExpectedVersion
    POSITION_DEFAULT = -1.freeze
    NOT_RESOLVED = Object.new.freeze

    def self.any
      new(:any)
    end

    def self.none
      new(:none)
    end

    def self.auto
      new(:auto)
    end

    attr_reader :value

    def initialize(value)
      @value = value
      invalid_version! unless [Integer, :any, :none, :auto].any? {|i| i === value}
    end

    def any?
      value.equal?(:any)
    end

    def resolve_for(stream, &resolver)
      invalid_version! unless allowed?(stream)

      case value
      when Integer
        value
      when :any
        nil
      when :none
        POSITION_DEFAULT
      when :auto
        resolver && resolver.call(stream) || POSITION_DEFAULT
      else
        invalid_version!
      end
    end

    private

    def allowed?(stream)
      any? || !stream.global?
    end

    def invalid_version!
      raise InvalidExpectedVersion
    end
  end
end<commit_msg>Inline conditions.<commit_after>module RubyEventStore
  class ExpectedVersion
    POSITION_DEFAULT = -1.freeze
    NOT_RESOLVED = Object.new.freeze

    def self.any
      new(:any)
    end

    def self.none
      new(:none)
    end

    def self.auto
      new(:auto)
    end

    attr_reader :value

    def initialize(value)
      @value = value
      invalid_version! unless [Integer, :any, :none, :auto].any? {|i| i === value}
    end

    def any?
      value.equal?(:any)
    end

    def resolve_for(stream, &resolver)
      invalid_version! if stream.global? && !any?

      case value
      when Integer
        value
      when :any
        nil
      when :none
        POSITION_DEFAULT
      when :auto
        resolver && resolver.call(stream) || POSITION_DEFAULT
      else
        invalid_version!
      end
    end

    private

    def invalid_version!
      raise InvalidExpectedVersion
    end
  end
end
{'fraction_non_alphanumeric': 0.0804416403785489, 'fraction_numerical': 0.0010515247108307045, 'mean_word_length': 1.9827586206896552, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3956103', 'n_tokens_mistral': 599, 'n_tokens_neox': 576, 'n_words': 154}