Sha256: ff0ddccae2c75f46345636c21a97d38f2fc3ee523429aed40204e7f204048a81

Contents?: true

Size: 1022 Bytes

Versions: 4

Compression:

Stored size: 1022 Bytes

Contents

module Pronto
  class Message
    attr_reader :path, :line, :level, :msg, :commit_sha

    LEVELS = [:info, :warning, :error, :fatal]

    def initialize(path, line, level, msg, commit_sha = nil)
      unless LEVELS.include?(level)
        raise ::ArgumentError, "level should be set to one of #{LEVELS}"
      end

      @path = path
      @line = line
      @level = level
      @msg = msg
      @commit_sha = commit_sha
      @commit_sha ||= line.commit_sha if line
    end

    def full_path
      repo.path.join(path) if repo
    end

    def repo
      line.patch.repo if line
    end

    def ==(other)
      comparison_attributes.all? do |attribute|
        send(attribute) == other.send(attribute)
      end
    end

    alias_method :eql?, :==

    def hash
      comparison_attributes.reduce(0) do |hash, attribute|
        hash ^ send(attribute).hash
      end
    end

    private

    def comparison_attributes
      line ? [:path, :msg, :level, :line] : [:path, :msg, :level, :commit_sha]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pronto-0.5.3 lib/pronto/message.rb
pronto-0.5.2 lib/pronto/message.rb
pronto-0.5.1 lib/pronto/message.rb
pronto-0.5.0 lib/pronto/message.rb