Class: Ocran::RuntimeEnvironment
- Inherits:
-
Object
- Object
- Ocran::RuntimeEnvironment
- Defined in:
- lib/ocran/runtime_environment.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#load_path ⇒ Object
readonly
Returns the value of attribute load_path.
-
#loaded_features ⇒ Object
readonly
Returns the value of attribute loaded_features.
-
#pwd ⇒ Object
readonly
Returns the value of attribute pwd.
Instance Method Summary collapse
-
#expand_path(path) ⇒ Object
Expands the given path using the working directory stored in this instance as the base.
- #find_load_path(path) ⇒ Object
-
#initialize ⇒ RuntimeEnvironment
constructor
A new instance of RuntimeEnvironment.
Constructor Details
#initialize ⇒ RuntimeEnvironment
Returns a new instance of RuntimeEnvironment.
15 16 17 18 19 20 |
# File 'lib/ocran/runtime_environment.rb', line 15 def initialize @env = ENV.to_hash.freeze @load_path = $LOAD_PATH.dup.freeze @loaded_features = $LOADED_FEATURES.dup.freeze @pwd = Dir.pwd.freeze end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
13 14 15 |
# File 'lib/ocran/runtime_environment.rb', line 13 def env @env end |
#load_path ⇒ Object (readonly)
Returns the value of attribute load_path.
13 14 15 |
# File 'lib/ocran/runtime_environment.rb', line 13 def load_path @load_path end |
#loaded_features ⇒ Object (readonly)
Returns the value of attribute loaded_features.
13 14 15 |
# File 'lib/ocran/runtime_environment.rb', line 13 def loaded_features @loaded_features end |
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
13 14 15 |
# File 'lib/ocran/runtime_environment.rb', line 13 def pwd @pwd end |
Instance Method Details
#expand_path(path) ⇒ Object
Expands the given path using the working directory stored in this instance as the base. This method resolves relative paths to absolute paths, ensuring they are fully qualified based on the working directory stored within this instance.
26 27 28 |
# File 'lib/ocran/runtime_environment.rb', line 26 def (path) File.(path, @pwd) end |
#find_load_path(path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ocran/runtime_environment.rb', line 30 def find_load_path(path) path = Pathname.new(path) unless path.is_a?(Pathname) if path.absolute? # For an absolute path feature, find the load path that contains the feature # and determine the longest matching path (most specific path). @load_path.select { |load_path| path.subpath?((load_path)) } .max_by { |load_path| (load_path).length } else # For a relative path feature, find the load path where the expanded feature exists # and select the longest load path (most specific path). @load_path.select { |load_path| path.(load_path).exist? } .max_by { |load_path| load_path.length } end end |