Sha256: c33152f831202a645394da8f4cdf6f1291c07d94f27a9c61ff9d600c746b47f1

Contents?: true

Size: 521 Bytes

Versions: 7

Compression:

Stored size: 521 Bytes

Contents

require 'set'

# This is a hack that I don't want to ever use anywhere else or repeat EVER, but we need enums to be
# an Array to pass schema validation. But we also want fast lookup!

class ArraySet < Array
  def include?(obj)
    if !defined? @values
      @values = Set.new
      self.each { |x| @values << convert_to_float_if_numeric(x) }
    end
    @values.include?(convert_to_float_if_numeric(obj))
  end

  private

  def convert_to_float_if_numeric(value)
    value.is_a?(Numeric) ? value.to_f : value
  end
end

Version data entries

7 entries across 6 versions & 3 rubygems

Version Path
json-schema-ouidou-2.9.1 lib/json-schema/util/array_set.rb
json-schema-ouidou-2.9.0 lib/json-schema/util/array_set.rb
json-schema-3.0.0 lib/json-schema/util/array_set.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/lib/json-schema/util/array_set.rb
mountapi-0.11.1 vendor/json-schema/lib/json-schema/util/array_set.rb
json-schema-2.8.1 lib/json-schema/util/array_set.rb
json-schema-2.8.0 lib/json-schema/util/array_set.rb