Sha256: 8539c450e6f90661fd898a126dc6d1bf0a027c37c4ee45dbea35804b5ad01721

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

# A complete web framework for Ruby
#
# @since 0.1.0
#
# @see http://hanamirb.org
module Hanami
  @_mutex = Mutex.new
  @_bundled = {}

  def self.app
    @_mutex.synchronize do
      unless defined?(@_app)
        raise AppLoadError,
              "Hanami.app is not yet configured. " \
              "You may need to `require \"hanami/setup\"` to load your config/app.rb file."
      end

      @_app
    end
  end

  def self.app?
    defined?(@_app)
  end

  def self.app=(klass)
    @_mutex.synchronize do
      if defined?(@_app)
        raise AppLoadError, "Hanami.app is already configured."
      end

      @_app = klass unless klass.name.nil?
    end
  end

  def self.env
    ENV.fetch("HANAMI_ENV") { ENV.fetch("RACK_ENV", "development") }.to_sym
  end

  def self.env?(*names)
    names.map(&:to_sym).include?(env)
  end

  def self.logger
    app[:logger]
  end

  def self.prepare
    app.prepare
  end

  def self.boot
    app.boot
  end

  def self.shutdown
    app.shutdown
  end

  def self.bundled?(gem_name)
    @_mutex.synchronize do
      @_bundled[gem_name] ||= begin
        gem(gem_name)
        true
      rescue Gem::LoadError
        false
      end
    end
  end

  def self.bundler_groups
    [:plugins]
  end

  require_relative "hanami/version"
  require_relative "hanami/errors"
  require_relative "hanami/extensions"
  require_relative "hanami/app"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-2.0.0.beta1.1 lib/hanami.rb
hanami-2.0.0.beta1 lib/hanami.rb