Class: Pronto::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/message.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, line, level, msg, commit_sha = nil, runner = nil) ⇒ Message

Returns a new instance of Message.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pronto/message.rb', line 7

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

Instance Attribute Details

#commit_shaObject (readonly)

Returns the value of attribute commit_sha.



3
4
5
# File 'lib/pronto/message.rb', line 3

def commit_sha
  @commit_sha
end

#levelObject (readonly)

Returns the value of attribute level.



3
4
5
# File 'lib/pronto/message.rb', line 3

def level
  @level
end

#lineObject (readonly)

Returns the value of attribute line.



3
4
5
# File 'lib/pronto/message.rb', line 3

def line
  @line
end

#msgObject (readonly)

Returns the value of attribute msg.



3
4
5
# File 'lib/pronto/message.rb', line 3

def msg
  @msg
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/pronto/message.rb', line 3

def path
  @path
end

#runnerObject (readonly)

Returns the value of attribute runner.



3
4
5
# File 'lib/pronto/message.rb', line 3

def runner
  @runner
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



29
30
31
32
33
# File 'lib/pronto/message.rb', line 29

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

#full_pathObject



21
22
23
# File 'lib/pronto/message.rb', line 21

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

#hashObject



37
38
39
40
41
# File 'lib/pronto/message.rb', line 37

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

#repoObject



25
26
27
# File 'lib/pronto/message.rb', line 25

def repo
  line.patch.repo if line
end

#to_hObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/pronto/message.rb', line 43

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