lib/ecoportal/api/common/content/array_model.rb in ecoportal-api-v2-0.8.8 vs lib/ecoportal/api/common/content/array_model.rb in ecoportal-api-v2-0.8.9
- old
+ new
@@ -1,11 +1,12 @@
module Ecoportal
module API
module Common
module Content
# Class to handle a plain Array embedded in a Hashed model.
- # @note its purpose is to handle an Array of basic objects (i.e. `Date`, `String`, `Number`)
+ # @note
+ # - Its purpose is to handle an Array of basic objects (i.e. `Date`, `String`, `Number`)
class ArrayModel < Content::DoubleModel
class TypeMismatchedComparison < Exception
def initialize (this: nil, that: msg = "Trying to compare objects with different behavior.")
if this
msg += " From object with 'order_matters: #{this.order_matters?}' and 'uniq: #{this.uniq?}'."
@@ -220,18 +221,19 @@
end
def insert_one(value, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
i = index(value)
return i if (i && uniq?)
-
pos = case
when used_param?(pos)
- pos
+ pos || length
when used_param?(before)
- index(before)
+ before ? index(before) : length
when used_param?(after)
- if i = index(after)
- i + 1
+ if after
+ if i = index(after) then i + 1 end
+ else
+ length
end
else
length
end