Class: Kaisoku::Entity

Inherits:
Struct
  • Object
show all
Defined in:
lib/kaisoku/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter:, identifier:, file:, line: nil, avg_duration_ms: nil, last_status: nil, last_failed_at: nil, failure_count: 0) ⇒ Entity

Returns a new instance of Entity.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kaisoku/entity.rb', line 15

def initialize(
  adapter:,
  identifier:,
  file:,
  line: nil,
  avg_duration_ms: nil,
  last_status: nil,
  last_failed_at: nil,
  failure_count: 0
)
  super(
    adapter: adapter.to_s,
    identifier: identifier.to_s,
    file: normalize_file(file),
    line: line,
    avg_duration_ms: avg_duration_ms,
    last_status: last_status,
    last_failed_at: last_failed_at,
    failure_count: failure_count.to_i
  )
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter

Returns:

  • (Object)

    the current value of adapter



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def adapter
  @adapter
end

#avg_duration_msObject

Returns the value of attribute avg_duration_ms

Returns:

  • (Object)

    the current value of avg_duration_ms



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def avg_duration_ms
  @avg_duration_ms
end

#failure_countObject

Returns the value of attribute failure_count

Returns:

  • (Object)

    the current value of failure_count



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def failure_count
  @failure_count
end

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def file
  @file
end

#identifierObject

Returns the value of attribute identifier

Returns:

  • (Object)

    the current value of identifier



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def identifier
  @identifier
end

#last_failed_atObject

Returns the value of attribute last_failed_at

Returns:

  • (Object)

    the current value of last_failed_at



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def last_failed_at
  @last_failed_at
end

#last_statusObject

Returns the value of attribute last_status

Returns:

  • (Object)

    the current value of last_status



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def last_status
  @last_status
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



4
5
6
# File 'lib/kaisoku/entity.rb', line 4

def line
  @line
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/kaisoku/entity.rb', line 63

def eql?(other)
  other.is_a?(Entity) && other.id == id
end

#failed?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/kaisoku/entity.rb', line 41

def failed?
  last_status == 'failed'
end

#hashObject



67
68
69
# File 'lib/kaisoku/entity.rb', line 67

def hash
  id.hash
end

#idObject



37
38
39
# File 'lib/kaisoku/entity.rb', line 37

def id
  "#{adapter}:#{identifier}"
end

#with_runtime(avg_duration_ms: self.avg_duration_ms, last_status: self.last_status, last_failed_at: self.last_failed_at, failure_count: self.failure_count) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kaisoku/entity.rb', line 45

def with_runtime(
  avg_duration_ms: self.avg_duration_ms,
  last_status: self.last_status,
  last_failed_at: self.last_failed_at,
  failure_count: self.failure_count
)
  self.class.new(
    adapter: adapter,
    identifier: identifier,
    file: file,
    line: line,
    avg_duration_ms: avg_duration_ms,
    last_status: last_status,
    last_failed_at: last_failed_at,
    failure_count: failure_count
  )
end