Sha256: 112db016c92bd2b7f62e96584bcf51cd54f18b181270a4d3810c94074997b15c

Contents?: true

Size: 742 Bytes

Versions: 2

Compression:

Stored size: 742 Bytes

Contents

module LogCabin
  ##
  # Define a collection of modules in a local dir
  class DirCollection < BaseCollection
    attr_reader :load_path

    def initialize(params = {})
      @load_path = params[:load_path] || raise('Load path must be provided')
      @load_path = [@load_path] if @load_path.is_a? String
      super
    end

    ##
    # Method for finding modules to load
    def find(name)
      cache(name) { load_class_from_module(find_file(name)) }
    end

    private

    ##
    # Check module path for module
    def find_file(name)
      @load_path.each do |dir|
        file_path = File.join(dir, "#{name}.rb")
        return file_path if File.exist? file_path
      end
      raise("Module #{name} not found")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logcabin-0.1.1 lib/logcabin/dircollection.rb
logcabin-0.1.0 lib/logcabin/dircollection.rb