Sha256: b0d99f69525f6eb02e46127eb9ff4382f072e7af712539a7900d7fedb9192acc

Contents?: true

Size: 1.21 KB

Versions: 11

Compression:

Stored size: 1.21 KB

Contents

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

    LEVELS = %i[info warning error fatal].freeze

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

      @path = path
      @line = line
      @level = level
      @msg = msg
      @runner = runner
      @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 eql? ==

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

    def to_h
      {
        path: path,
        line: line,
        level: level,
        msg: msg,
        commit_sha: commit_sha,
        runner: @runner && @runner.title
      }
    end

    private

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pronto-0.11.3 lib/pronto/message.rb
pronto-0.11.2 lib/pronto/message.rb
pronto-0.11.1 lib/pronto/message.rb
pronto-0.11.0 lib/pronto/message.rb
pronto-0.10.0 lib/pronto/message.rb
pronto-0.9.5 lib/pronto/message.rb
pronto-0.9.4 lib/pronto/message.rb
pronto-0.9.3 lib/pronto/message.rb
pronto-0.9.2 lib/pronto/message.rb
pronto-0.9.1 lib/pronto/message.rb
pronto-0.9.0 lib/pronto/message.rb