Sha256: b0cf00ce0160a82891565ab7d7442b127228afbbe702b6cc93692e5cf51d4e82

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require 'wcc/contentful/rails'

require_relative './app/exceptions'
require_relative './app/configuration'
require_relative './app/markdown_renderer'

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::Model.schema.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

16 entries across 16 versions & 1 rubygems

Version Path
wcc-contentful-app-1.6.0 lib/wcc/contentful/app.rb
wcc-contentful-app-1.5.1 lib/wcc/contentful/app.rb
wcc-contentful-app-1.5.0 lib/wcc/contentful/app.rb
wcc-contentful-app-1.5.0.rc1 lib/wcc/contentful/app.rb
wcc-contentful-app-1.4.0 lib/wcc/contentful/app.rb
wcc-contentful-app-1.4.0.rc3 lib/wcc/contentful/app.rb
wcc-contentful-app-1.4.0.rc2 lib/wcc/contentful/app.rb
wcc-contentful-app-1.3.2 lib/wcc/contentful/app.rb
wcc-contentful-app-1.4.0.rc1 lib/wcc/contentful/app.rb
wcc-contentful-app-1.3.1 lib/wcc/contentful/app.rb
wcc-contentful-app-1.3.0 lib/wcc/contentful/app.rb
wcc-contentful-app-1.2.1 lib/wcc/contentful/app.rb
wcc-contentful-app-1.2.0 lib/wcc/contentful/app.rb
wcc-contentful-app-1.1.2 lib/wcc/contentful/app.rb
wcc-contentful-app-1.1.1 lib/wcc/contentful/app.rb
wcc-contentful-app-1.1.0 lib/wcc/contentful/app.rb