Sha256: bdb31520ac44bb40de5905a03c6d8e0be697f824ce2c5370fe56a932c8041339

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'wcc/contentful/rails'

require_relative './app/rails'
require_relative './app/exceptions'
require_relative './app/configuration'

module WCC::Contentful::App
  class << self
    attr_reader :initialized

    # Gets the current configuration, after calling WCC::Contentful::App.configure
    attr_reader :configuration
  end

  def self.configure
    if initialized || WCC::Contentful.initialized
      raise WCC::Contentful::InitializationError, 'Cannot configure after initialization'
    end

    WCC::Contentful.configure do |wcc_contentful_config|
      if @configuration&.wcc_contentful_config != wcc_contentful_config
        @configuration = Configuration.new(wcc_contentful_config)
      end
      yield(configuration)
    end

    configuration.validate!

    configuration
  end

  def self.init!
    raise ArgumentError, 'Please first call WCC::Contentful::App.configure' if configuration.nil?

    WCC::Contentful.init!

    # Extend all model types w/ validation & extra fields
    WCC::Contentful.types.each_value do |t|
      file = File.dirname(__FILE__) + "/model/#{t.name.underscore}.rb"
      require file if File.exist?(file)
    end

    @db_connected =
      begin
        ::ActiveRecord::Base.connection_pool.with_connection(&:active?)
      rescue StandardError
        false
      end

    @configuration = WCC::Contentful::App::Configuration::FrozenConfiguration.new(
      configuration,
      WCC::Contentful.configuration
    )
    @initialized = true
  end

  def self.db_connected?
    @db_connected
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wcc-contentful-app-1.0.5 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.4 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.3 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.2 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.1 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.0 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.0.pre.rc3 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.0.pre.rc2 lib/wcc/contentful/app.rb
wcc-contentful-app-1.0.0.pre.rc1 lib/wcc/contentful/app.rb