lib/attributor/families/numeric.rb in attributor-5.4 vs lib/attributor/families/numeric.rb in attributor-5.5
- old
+ new
@@ -1,15 +1,28 @@
# Abstract type for the 'numeric' family
module Attributor
- class Numeric
+ module Numeric
+ extend ActiveSupport::Concern
include Type
- def self.native_type
- raise NotImplementedError
- end
+ module ClassMethods
+
+ def native_type
+ raise NotImplementedError
+ end
- def self.family
- 'numeric'
+ def family
+ 'numeric'
+ end
+
+ def as_json_schema( shallow: false, example: nil, attribute_options: {} )
+ h = super
+ opts = ( self.respond_to?(:options) ) ? self.options.merge( attribute_options ) : attribute_options
+ h[:minimum] = opts[:min] if opts[:min]
+ h[:maximum] = opts[:max] if opts[:max]
+ # We're not explicitly setting false to exclusiveMinimum and exclusiveMaximum (as that's the default)
+ h
+ end
end
end
end