Skip to content

Commit

Permalink
Merge pull request #6298 from ministryofjustice/mw/restore-extensions
Browse files Browse the repository at this point in the history
Restore `IntegerExtension` and `NilExtension`
  • Loading branch information
mpw5 authored Dec 1, 2023
2 parents 926e08d + cd0fb67 commit 0470996
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/interfaces/api/entities/cclf/base_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BaseClaim < API::Entities::BaseEntity
private

def actual_trial_length_or_one
object.actual_trial_length || 1
object.actual_trial_length.or_one
end

# case type adapter requires access to claim object
Expand Down
8 changes: 4 additions & 4 deletions app/interfaces/api/entities/ccr/base_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def defendants_with_main_first
end

def estimated_trial_length_or_one
object.estimated_trial_length || 1
object.estimated_trial_length.or_one
end

def actual_trial_length_or_one
object.actual_trial_length || 1
object.actual_trial_length.or_one
end

def retrial_actual_length_or_one
object.retrial_actual_length || 1
object.retrial_actual_length.or_one
end

def retrial_estimated_length_or_one
object.retrial_estimated_length || 1
object.retrial_estimated_length.or_one
end

def adapted_advocate_category
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/00_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ class FalseClass
include Extensions::BooleanExtension::False
end

class Integer
include Extensions::IntegerExtension
end

class NilClass
include Extensions::NilExtension
end
7 changes: 7 additions & 0 deletions lib/extensions/integer_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Extensions
module IntegerExtension
def or_one
[self, 1].compact.max
end
end
end
7 changes: 7 additions & 0 deletions lib/extensions/nil_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Extensions
module NilExtension
def or_one
1
end
end
end

0 comments on commit 0470996

Please sign in to comment.