Skip to content

Commit

Permalink
Extend supported values for Nginx::Size and Nginx::Time
Browse files Browse the repository at this point in the history
Allow raw integers and add support for combination of multiple units.
  • Loading branch information
smortex committed Jul 5, 2023
1 parent 92aa72c commit 89496d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
10 changes: 8 additions & 2 deletions spec/type_aliases/size_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
it { is_expected.to allow_value('1024K') }
it { is_expected.to allow_value('1m') }
it { is_expected.to allow_value('1M') }
it { is_expected.to allow_value(1) }
it { is_expected.to allow_value(1024) }
it { is_expected.to allow_value('1') }
it { is_expected.to allow_value('1024') }

it { is_expected.not_to allow_value(:undef) }
it { is_expected.not_to allow_value(1) }
it { is_expected.not_to allow_value(1024) }
it { is_expected.not_to allow_value('') }
it { is_expected.not_to allow_value(-1) }
it { is_expected.not_to allow_value(-1024) }
it { is_expected.not_to allow_value('-1') }
it { is_expected.not_to allow_value('-1024') }
it { is_expected.not_to allow_value('0.1k') }
it { is_expected.not_to allow_value('0.1K') }
it { is_expected.not_to allow_value('0.1m') }
Expand Down
11 changes: 9 additions & 2 deletions spec/type_aliases/time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
it { is_expected.to allow_value('1d') }
it { is_expected.to allow_value('1M') }
it { is_expected.to allow_value('1y') }
it { is_expected.to allow_value('1y 2M 3w 4d 5h 6m 7ms') }
it { is_expected.to allow_value(1) }
it { is_expected.to allow_value(10) }
it { is_expected.to allow_value('1') }
it { is_expected.to allow_value('10') }

it { is_expected.not_to allow_value(:undef) }
it { is_expected.not_to allow_value(1) }
it { is_expected.not_to allow_value(10) }
it { is_expected.not_to allow_value(-1) }
it { is_expected.not_to allow_value(-10) }
it { is_expected.not_to allow_value('-1') }
it { is_expected.not_to allow_value('-10') }
it { is_expected.not_to allow_value('') }
it { is_expected.not_to allow_value('10S') }
it { is_expected.not_to allow_value('10.0s') }
Expand Down
5 changes: 4 additions & 1 deletion types/size.pp
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
type Nginx::Size = Pattern[/^\d+[k|K|m|M]?$/]
type Nginx::Size = Variant[
Integer[0],
Pattern[/\A\d+[k|K|m|M]?\z/],
]
5 changes: 4 additions & 1 deletion types/time.pp
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
type Nginx::Time = Pattern[/^\d+(ms|s|m|h|d|w|M|y)?$/]
type Nginx::Time = Variant[
Integer[0],
Pattern[/^(?!$)((\d+y *)?(\d+M *)?(\d+w *)?(\d+d *)?(\d+h *)?(\d+m *)?(\d+s *)?(\d+ms)?|\d+)$/],
]

0 comments on commit 89496d2

Please sign in to comment.