Sha256: e2d168b82cddc92c518b5f1098add87920caa72f320c965b533eb5875381d710

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

require 'json'
require 'time'
require 'date'

module FastSerializer
  require_relative 'fast_serializer/cache'
  require_relative 'fast_serializer/cache/active_support_cache'
  require_relative 'fast_serializer/serialization_context'
  require_relative 'fast_serializer/serialized_field'
  require_relative 'fast_serializer/serializer'
  require_relative 'fast_serializer/array_serializer'

  class << self
    @cache = nil

    # Get the global cache implementation used for storing cacheable serializers.
    def cache
      @cache
    end

    # Set the global cache implementation used for storing cacheable serializers.
    # The cache implementation should implement the +fetch+ method as defined in
    # FastSerializer::Cache. By default no cache is set so caching won't do anything.
    #
    # In a Rails app, you can initialize the cache by simply passing in the value :rails
    # to use the default Rails.cache. You can also directly pass in an ActiveSupportCache::Store.
    def cache=(cache)
      if cache == :rails
        cache = Cache::ActiveSupportCache.new(Rails.cache)
      elsif defined?(ActiveSupport::Cache::Store) && cache.is_a?(ActiveSupport::Cache::Store)
        cache = Cache::ActiveSupportCache.new(cache)
      end
      if cache && !cache.is_a?(FastSerializer::Cache)
        raise ArgumentError.new("The cache must be a FastSerializer::Cache or ActiveSupport::Cache::Store")
      end
      @cache = cache
    end
  end

  # Exception raised when there is a circular reference serializing a model dependent on itself.
  class CircularReferenceError < StandardError
    def initialize(model)
      super("Circular refernce on #{model.inspect}")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fast_serializer-1.1.1 lib/fast_serializer.rb
fast_serializer-1.1.0 lib/fast_serializer.rb
fast_serializer-1.0.2 lib/fast_serializer.rb