Sha256: 511bf2a60102beee72f025d1f00912e0386118e33b9d410d74e170fd093b2863

Contents?: true

Size: 437 Bytes

Versions: 5

Compression:

Stored size: 437 Bytes

Contents

class Temping::NamespaceFactory
  def initialize(name)
    @name = name
  end

  def klass
    @klass ||= @name.split("::").reduce(Object) { |parent, name_part| build(parent, name_part) }
  end

  private

  def build(parent, name_part)
    parent.const_get(name_part)
  rescue NameError
    parent.const_set(
      name_part,
      Module.new do
        def self.defined_by_temping?
          true
        end
      end
    )
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
temping-4.3.0 lib/temping/namespace_factory.rb
temping-4.2.0 lib/temping/namespace_factory.rb
temping-4.1.1 lib/temping/namespace_factory.rb
temping-4.1.0 lib/temping/namespace_factory.rb
temping-4.0.0 lib/temping/namespace_factory.rb