Sha256: 906f9df285a3a4b16cd50d8132fc0ae307f712c156a4507090511f3f44c3b580

Contents?: true

Size: 1.7 KB

Versions: 16

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

# This object contains all the configuration options for the `wcc-contentful` gem.
class WCC::Contentful::App::Configuration
  # TODO: things to configure in the app?
  ATTRIBUTES = %i[
    preview_password
  ].freeze

  # Sets the password that will be checked when the query string contains `preview=`,
  # if it matches, then the Contentful entries are fetched via the preview API.
  attr_accessor :preview_password

  attr_reader :wcc_contentful_config

  delegate(*WCC::Contentful::Configuration::ATTRIBUTES, to: :wcc_contentful_config)
  delegate(*(WCC::Contentful::Configuration::ATTRIBUTES.map { |a| "#{a}=" }),
    to: :wcc_contentful_config)

  def initialize(wcc_contentful_config)
    @wcc_contentful_config = wcc_contentful_config
    @preview_password = ENV['CONTENTFUL_PREVIEW_PASSWORD']
  end

  # Validates the configuration, raising ArgumentError if anything is wrong.  This
  # is called by WCC::Contentful::App.init!
  def validate!
    wcc_contentful_config.validate!
  end

  def frozen?
    false
  end

  class FrozenConfiguration
    attr_reader(*ATTRIBUTES)

    attr_reader :wcc_contentful_config

    delegate(*WCC::Contentful::Configuration::ATTRIBUTES, to: :wcc_contentful_config)

    def initialize(configuration, frozen_wcc_contentful_config)
      unless frozen_wcc_contentful_config.frozen?
        raise ArgumentError, 'Please first freeze the wcc_contentful_config'
      end

      @wcc_contentful_config = frozen_wcc_contentful_config

      ATTRIBUTES.each do |att|
        val = configuration.public_send(att)
        val.freeze if val.respond_to?(:freeze)
        instance_variable_set("@#{att}", val)
      end
    end

    def frozen?
      true
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
wcc-contentful-app-1.2.0 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.1.2 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.1.1 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.1.0 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.8 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.7 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.6 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.5 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.4 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.3 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.2 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.1 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.0 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.0.pre.rc3 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.0.pre.rc2 lib/wcc/contentful/app/configuration.rb
wcc-contentful-app-1.0.0.pre.rc1 lib/wcc/contentful/app/configuration.rb