Module: Levels::Runtime
- Included in:
- Input::Ruby::DSL, LazyEvaluator::DSL
- Defined in:
- lib/levels/runtime.rb
Overview
Public: Methods in this module are available within any Ruby input. You may extend it with any additonal methods you require.
Constant Summary collapse
- FileNotFoundError =
Class.new(RuntimeError)
Instance Method Summary collapse
-
#file(file_path) ⇒ Object
Public: Read the value from a file on disk.
Instance Method Details
#file(file_path) ⇒ Object
Public: Read the value from a file on disk. The file will not be read until the key is accessed.
file_path - String path to the file. The path may be absolute,
or relative to the Ruby file calling this function.
Returns a Proc that reads the file when called. That proc raises Levels::Ruby::FileNotFoundError if the file does
not exist.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/levels/runtime.rb', line 17 def file(file_path) return nil if file_path.nil? caller_path = Pathname.new(caller[0]).dirname -> do path = caller_path + file_path if path.exist? path.read else raise FileNotFoundError, path.to_s end end end |