Module: Serega::SeregaPlan::ClassMethods

Included in:
Serega::SeregaPlan
Defined in:
lib/serega/plan.rb

Overview

SeregaPlan class methods

Instance Method Summary collapse

Instance Method Details

#call(opts) ⇒ SeregaPlan

Constructs plan of attributes that should be serialized.

Options Hash (opts):

  • :only (Hash)

    The only attributes to serialize

  • :except (Hash)

    Attributes to hide

  • :with (Hash)

    Attributes (usually marked hide: true) to serialize additionally



25
26
27
28
29
30
# File 'lib/serega/plan.rb', line 25

def call(opts)
  max_cache_size = serializer_class.config.max_cached_plans_per_serializer_count
  return new(nil, opts) if max_cache_size.zero?

  cached_plan_for(opts, max_cache_size)
end

#data_class_for(point_names) ⇒ Class

Returns (and caches) the Data class for the given set of field names. Uses the Array as cache key so the same Data class is reused across all plan instances with identical fields.



40
41
42
# File 'lib/serega/plan.rb', line 40

def data_class_for(point_names)
  (@data_classes ||= {})[point_names] ||= Data.define(*point_names)
end