Class: Glslkit::Resolvers::FileSystem
- Inherits:
-
Object
- Object
- Glslkit::Resolvers::FileSystem
- Defined in:
- lib/glslkit/resolvers/file_system.rb
Overview
ディスク上のload_paths群に対して#includeのリクエストを解決する。 canonical_pathは常に、マッチしたload_pathからの相対パスとして表現される (例 "common/math.glsl")。絶対パスになることはない — この結果を元に作られるマニフェストはブラウザに配信されるものなので、 ローカルの絶対パスを漏らしてはならない。
Instance Method Summary collapse
-
#initialize(load_paths:) ⇒ FileSystem
constructor
A new instance of FileSystem.
- #read(request, from: nil) ⇒ Object
Constructor Details
#initialize(load_paths:) ⇒ FileSystem
Returns a new instance of FileSystem.
13 14 15 16 |
# File 'lib/glslkit/resolvers/file_system.rb', line 13 def initialize(load_paths:) @load_paths = load_paths.map { |path| File.(path) } @absolute_paths = {} # canonical_path => 絶対パス。相対探索のためのキャッシュ end |
Instance Method Details
#read(request, from: nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/glslkit/resolvers/file_system.rb', line 18 def read(request, from: nil) absolute = resolve_absolute_path(request, from) canonical = canonicalize(absolute) @absolute_paths[canonical] = absolute [canonical, File.read(absolute)] end |