Sha256: c31212596396525d3504a9161e2e8cfc4da5b2ae2e58cce92868b161f0da9513

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

# Handles Rails configurations for Consyncful
module Consyncful
  ##
  class Configuration
    attr_accessor :contentful_client_options,
                  :contentful_sync_options,
                  :locale,
                  :mongo_client,
                  :mongo_collection,
                  :content_tags,
                  :ignore_content_tags,
                  :preserve_contentful_timestamps

    def initialize
      @contentful_client_options = {}
      @contentful_sync_options = {}
      @locale = 'en-NZ'
      @mongo_client = :default
      @mongo_collection = 'contentful_models'
      @content_tags = []
      @ignore_content_tags = []
      @preserve_contentful_timestamps = false
    end

    def initial_sync_options
      options = { initial: true }
      options = options.reverse_merge(@contentful_sync_options)
      options.reverse_merge(DEFAULT_SYNC_OPTIONS)
    end

    def client_options
      options = @contentful_client_options
      options.reverse_merge!(DEFAULT_CLIENT_OPTIONS)
    end
  end

  DEFAULT_CLIENT_OPTIONS = {
    reuse_entries: true,
    api_url: 'cdn.contentful.com'
  }.freeze

  # see https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization
  DEFAULT_SYNC_OPTIONS = {
    limit: 100,
    type: 'all'
  }.freeze

  class << self
    def configuration
      @configuration ||= Configuration.new
    end

    def configure
      yield configuration
    end

    def client
      @client ||= Contentful::Client.new(Consyncful.configuration.client_options)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
consyncful-1.0.1 lib/consyncful/configuration.rb
consyncful-1.0.0 lib/consyncful/configuration.rb