-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ class Numeric < Object | |
Aggregate::Sum::Methods | ||
include Equalizer.new(:name, :required?, :size) | ||
|
||
DEFAULT_SIZE = (-::Float::INFINITY..::Float::INFINITY).freeze | ||
|
||
inheritable_alias(range: :size) | ||
|
||
# The attribute type | ||
|
@@ -38,10 +36,12 @@ def self.type | |
# @api private | ||
def initialize(_name, options = EMPTY_HASH) | ||
super | ||
size = options.fetch(:size, self.class::DEFAULT_SIZE).to_inclusive | ||
@type = type.new do | ||
minimum size.first | ||
maximum size.last | ||
if options.key?(:size) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cored
via email
Author
Collaborator
|
||
size = options.fetch(:size).to_inclusive | ||
This comment has been minimized.
Sorry, something went wrong.
dkubb
Owner
|
||
@type = type.new do | ||
minimum size.first | ||
maximum size.last | ||
end | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
context 'without :size option passed to constructor' do | ||
let(:object) { described_class.new(:id) } | ||
|
||
it { should eql(-Float::MAX..Float::MAX) } | ||
it { should eql(Axiom::Types::NegativeInfinity..Axiom::Types::Infinity) } | ||
This comment has been minimized.
Sorry, something went wrong.
dkubb
Owner
|
||
end | ||
|
||
context 'with :size option passed to constructor' do | ||
|
This is perfect. We want to minimize creating unnecessary types and reuse existing types as much as possible.
The only time we should be creating a new type is when we need to further constraint an existing one.