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.

Parameters:

  • opts

    Serialization parameters

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

Returns:



23
24
25
26
27
28
# File 'lib/serega/plan.rb', line 23

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.

Parameters:

  • point_names (Array<Symbol>)

    Attribute names for the Data members

Returns:

  • (Class)

    Subclass of Data



38
39
40
# File 'lib/serega/plan.rb', line 38

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