Sha256: 7fac92453f9d360ba1705bae87b4644fd77e7390f939011c948faf5a1d629d99

Contents?: true

Size: 960 Bytes

Versions: 7

Compression:

Stored size: 960 Bytes

Contents

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" if not @items.key? name
        @items[name]
      end
    end

    class << self
      @@resources = ResourceCollection.new

      def resources
        @@resources
      end
    end

    Spectre.register do |config|
      return if !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: Resources
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spectre-core-1.11.0 lib/spectre/resources.rb
spectre-core-1.10.0 lib/spectre/resources.rb
spectre-core-1.9.0 lib/spectre/resources.rb
spectre-core-1.8.4 lib/spectre/resources.rb
spectre-core-1.8.3 lib/spectre/resources.rb
spectre-core-1.8.2 lib/spectre/resources.rb
spectre-core-1.8.1 lib/spectre/resources.rb