Module: Serega::Map::ClassMethods

Included in:
Serega::Map
Defined in:
lib/serega/map.rb

Instance Method Summary collapse

Instance Method Details

#call(opts) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/serega/map.rb', line 6

def call(opts)
  @cache ||= {}
  cache_key = opts.to_s

  @cache[cache_key] ||= begin
    modifiers = {
      only: opts&.[](:only) || FROZEN_EMPTY_HASH,
      except: opts&.[](:except) || FROZEN_EMPTY_HASH,
      with: opts&.[](:with) || FROZEN_EMPTY_HASH
    }

    construct_map(serializer_class, **modifiers).tap do
      @cache.shift if @cache.length >= serializer_class.config[:max_cached_map_per_serializer_count]
    end
  end
end