Sha256: d269e74562ae2ef2c076e4b121853cc3f63a643933e97ddd2f0108f2626850b9

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

require 'rom'
require 'concurrent'
require 'hanami/entity'
require 'hanami/repository'

module Hanami
  # Hanami persistence
  #
  # @since 0.1.0
  module Model
    require 'hanami/model/version'
    require 'hanami/model/error'
    require 'hanami/model/configuration'
    require 'hanami/model/configurator'
    require 'hanami/model/mapping'
    require 'hanami/model/plugins'

    # @api private
    # @since 0.7.0
    @__repositories__ = Concurrent::Array.new

    class << self
      # @since 0.7.0
      # @api private
      attr_reader :config

      # @since 0.7.0
      # @api private
      attr_reader :loaded

      # @since 0.7.0
      # @api private
      alias loaded? loaded
    end

    # Configure the framework
    #
    # @since 0.1.0
    #
    # @example
    #   require 'hanami/model'
    #
    #   Hanami::Model.configure do
    #     adapter :sql, ENV['DATABASE_URL']
    #
    #     migrations 'db/migrations'
    #     schema     'db/schema.sql'
    #   end
    def self.configure(&block)
      @config = Configurator.build(&block)
      self
    end

    # Current configuration
    #
    # @since 0.1.0
    def self.configuration
      @configuration ||= Configuration.new(config)
    end

    # @since 0.7.0
    # @api private
    def self.repositories
      @__repositories__
    end

    # @since 0.7.0
    # @api private
    def self.container
      raise 'Not loaded' unless loaded?
      @container
    end

    # @since 0.1.0
    def self.load!(&blk)
      @container = configuration.load!(repositories, &blk)
      @loaded    = true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-model-1.0.0.beta2 lib/hanami/model.rb
hanami-model-1.0.0.beta1 lib/hanami/model.rb