Sha256: ee9ee7cac79af9d24b23c67f8433b85f9896ae29aacdd390a8215004b1a09367

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require_relative '../spectre'

require 'ostruct'

module Spectre
  module Resources
    class ResourceCollection
      def initialize
        @items = {}
      end

      def add name, path
        @items[name] = path
      end

      def [] name
        raise "Resource with name '#{name}' does not exist" unless @items.key? name

        @items[name]
      end
    end

    class << self
      @@resources = ResourceCollection.new

      def resources
        @@resources
      end
    end

    Spectre.register do |config|
      return unless config.key? 'resource_paths'

      config['resource_paths'].each do |resource_path|
        resource_files = Dir.glob File.join(resource_path, '**/*')

        resource_files.each do |file|
          file.slice! resource_path
          file = file[1..-1]
          @@resources.add file, File.expand_path(File.join resource_path, file)
        end
      end

      @@resources.freeze
    end

    Spectre.delegate :resources, to: self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spectre-core-1.12.0 lib/spectre/resources.rb