Sha256: 25de3e08d90e524860b80704cd19afd05c0ef7ae023beef2a4962249062f3e5c

Contents?: true

Size: 911 Bytes

Versions: 7

Compression:

Stored size: 911 Bytes

Contents

# frozen_string_literal: true

require "pakyow/support/inflector"
require "pakyow/support/makeable"

module Pakyow
  # Loads files that define an app aspect and names the objects appropriately.
  #
  class Loader
    def initialize(path)
      @path = path
    end

    def call(target)
      code = String.new
      target.__object_name.namespace.parts.each do |part|
        code << "module #{Support.inflector.camelize(part)}\n"
      end

      code << "class #{Support.inflector.camelize(target.__object_name.name)}\n"
      code << File.read(@path)
      code << "end\n"

      target.__object_name.namespace.parts.count.times do
        code << "end\n"
      end

      object = eval(code, TOPLEVEL_BINDING, @path, 1 - target.__object_name.namespace.parts.count - 1)

      if object.respond_to?(:__source_location)
        object.__source_location = [@path, 1]
      end

      object
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pakyow-core-1.0.6 lib/pakyow/loader.rb
pakyow-core-1.0.5 lib/pakyow/loader.rb
pakyow-core-1.0.4 lib/pakyow/loader.rb
pakyow-core-1.0.3 lib/pakyow/loader.rb
pakyow-core-1.0.2 lib/pakyow/loader.rb
pakyow-core-1.0.1 lib/pakyow/loader.rb
pakyow-core-1.0.0 lib/pakyow/loader.rb