push
travis-ci
32 of 32 new or added lines in 2 files covered. (100.0%)
133 of 136 relevant lines covered (97.79%)
3503.69 hits per line
1 |
module Activerecord |
26✔ |
2 |
module Transactionable |
26✔ |
3 |
class Result |
26✔ |
|
attr_reader :value, :result, :error, :type, :context, :nested, :attempt |
26✔ |
|
def initialize(value, context:, transaction_open:, attempt:, error: nil, type: nil) |
26✔ |
6 |
@value = value
|
2,938✔ |
7 |
@result = fail? ? 'fail' : 'success' |
2,938✔ |
8 |
@context = context
|
2,938✔ |
9 |
@nested = transaction_open ? true : false |
2,938✔ |
|
@attempt = attempt
|
2,938✔ |
11 |
@error = error
|
2,938✔ |
12 |
@type = type
|
2,938✔ |
13 |
end
|
|
14 |
|
|
15 |
def fail? |
26✔ |
16 |
value == false
|
3,640✔ |
17 |
end
|
|
18 |
|
|
19 |
def success? |
26✔ |
20 |
value == true
|
52✔ |
21 |
end
|
|
22 |
|
|
|
def to_h(skip_error: nil) |
26✔ |
24 |
diagnostic_data = { |
3,562✔ |
25 |
result: result,
|
|
26 |
type: type,
|
|
27 |
context: context,
|
|
28 |
nested: nested,
|
|
29 |
attempt: attempt,
|
|
30 |
} |
|
31 |
diagnostic_data.merge!( |
|
32 |
error: error.class.to_s,
|
|
33 |
message: error.message,
|
|
|
) if !skip_error && error
|
3,562✔ |
35 |
diagnostic_data |
3,562✔ |
36 |
end
|
|
37 |
|
|
|
def to_s(skip_error: nil) |
26✔ |
|
to_h(skip_error: skip_error).to_s
|
× |
40 |
end
|
|
41 |
end
|
|
42 |
end
|
|
43 |
end
|