Sha256: d3aaccd4db92e54b50a2620129c5b3bf8329b3886a28707123548893948c08a4

Contents?: true

Size: 1.45 KB

Versions: 15

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'pathname'

class Ree::Container
  class << self
    SEMAPHORE = Mutex.new
    private_constant :SEMAPHORE

    # singleton
    def instance
      SEMAPHORE.synchronize do
        @instance ||= begin
          self.new
        end
      end

      @instance
    end
  end

  include Ree::Args

  MOUNT_AS = [:fn, :object]

  attr_reader :packages_facade

  def initialize
    @packages_facade = Ree::PackagesFacade.new
    @object_compiler = Ree::ObjectCompiler.new(@packages_facade)
  end

  # @param [Ree::Package] package
  # @param [Symbol] object_name
  def compile(package, object_name)
    compile_object("#{package.name}/#{object_name}")
  end

  # @param [String] name_with_package
  # @return [Ree::Object]
  def compile_object(name_with_package)
    check_arg(name_with_package, :name_with_package, String)

    list = name_with_package.to_s.split('/')

    name = nil
    package_name = nil

    if list.size == 2
      package_name = list.first.to_sym
      name = list.last.to_sym
    else
      raise Ree::Error.new("'package/name' definition should be used to load object", :invalid_dsl_usage)
    end

    @packages_facade.get_loaded_package(package_name)
    @packages_facade.load_package_object(package_name, name)

    @object_compiler.call(package_name, name)
  end

  # @param [Symbol] package_name
  # @return [Ree::Package]
  def load_package(package_name)
    @packages_facade.load_entire_package(package_name)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ree-1.0.47 lib/ree/container.rb
ree-1.0.46 lib/ree/container.rb
ree-1.0.45 lib/ree/container.rb
ree-1.0.44 lib/ree/container.rb
ree-1.0.43 lib/ree/container.rb
ree-1.0.42 lib/ree/container.rb
ree-1.0.41 lib/ree/container.rb
ree-1.0.40 lib/ree/container.rb
ree-1.0.39 lib/ree/container.rb
ree-1.0.38 lib/ree/container.rb
ree-1.0.37 lib/ree/container.rb
ree-1.0.36 lib/ree/container.rb
ree-1.0.35 lib/ree/container.rb
ree-1.0.34 lib/ree/container.rb
ree-1.0.33 lib/ree/container.rb