Sha256: f11ba0e1e29783a7deda97a8899c722c9ccc241e465eb114b365bff6d6bd6559

Contents?: true

Size: 1008 Bytes

Versions: 3

Compression:

Stored size: 1008 Bytes

Contents

require 'concurrent'
require 'delegate'
require 'hanami/application'
require 'hanami/utils/class'
require 'hanami/utils/string'

module Hanami
  class Configuration
    class App < SimpleDelegator
      attr_reader :path_prefix

      def initialize(app, path_prefix)
        super(app)
        @path_prefix = path_prefix
      end
    end

    def initialize(&blk)
      @settings = Concurrent::Map.new
      instance_eval(&blk)
    end

    def mount(app, options)
      mounted[app] = App.new(app, options.fetch(:at))
    end

    def model(&blk)
      if block_given?
        settings.put_if_absent(:model, blk)
      else
        settings.fetch(:model)
      end
    end

    def mailer(&blk)
      settings.put_if_absent(:mailer, blk)
    end

    def mounted
      settings.fetch_or_store(:mounted, {})
    end

    def apps
      mounted.each_pair do |klass, app|
        yield(app) if klass.ancestors.include?(Hanami::Application)
      end
    end

    private

    attr_reader :settings
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-0.9.2 lib/hanami/configuration.rb
hanami-0.9.1 lib/hanami/configuration.rb
hanami-0.9.0 lib/hanami/configuration.rb