Class: Ocran::RuntimeEnvironment
- Inherits:
-
Object
- Object
- Ocran::RuntimeEnvironment
- Defined in:
- lib/ocran/runtime_environment.rb
Constant Summary collapse
- BUNDLER_SETUP_FEATURE =
Matches the bundler/setup feature by which
bundle execsets a process up, whatever prefix the bundler gem happens to be installed under. %r{[\\/]bundler[\\/]setup\.rb\z}
Instance Attribute Summary collapse
-
#activated_gems ⇒ Object
readonly
Returns the value of attribute activated_gems.
-
#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
-
#bundler_setup_loaded? ⇒ Boolean
Whether Bundler had already set this process up when the snapshot was taken.
-
#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.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ocran/runtime_environment.rb', line 20 def initialize @env = ENV.to_hash.freeze @load_path = $LOAD_PATH.dup.freeze @loaded_features = $LOADED_FEATURES.dup.freeze @pwd = Dir.pwd.freeze # The gems RubyGems had activated at this point. Under `bundle exec` # that is the entire bundle, activated before OCRAN's first line runs, # so a snapshot taken before the dependency run is what tells the build # environment's gems apart from the application's. @activated_gems = (defined?(Gem) ? Gem.loaded_specs.keys : []).freeze end |
Instance Attribute Details
#activated_gems ⇒ Object (readonly)
Returns the value of attribute activated_gems.
18 19 20 |
# File 'lib/ocran/runtime_environment.rb', line 18 def activated_gems @activated_gems end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
18 19 20 |
# File 'lib/ocran/runtime_environment.rb', line 18 def env @env end |
#load_path ⇒ Object (readonly)
Returns the value of attribute load_path.
18 19 20 |
# File 'lib/ocran/runtime_environment.rb', line 18 def load_path @load_path end |
#loaded_features ⇒ Object (readonly)
Returns the value of attribute loaded_features.
18 19 20 |
# File 'lib/ocran/runtime_environment.rb', line 18 def loaded_features @loaded_features end |
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
18 19 20 |
# File 'lib/ocran/runtime_environment.rb', line 18 def pwd @pwd end |
Instance Method Details
#bundler_setup_loaded? ⇒ Boolean
Whether Bundler had already set this process up when the snapshot was
taken. bundle exec arranges that through RUBYOPT (and, with newer
RubyGems, through the BUNDLER_SETUP variable), so bundler/setup is in
$LOADED_FEATURES before the command it runs gets to say anything.
36 37 38 |
# File 'lib/ocran/runtime_environment.rb', line 36 def bundler_setup_loaded? @loaded_features.any? { |feature| feature.to_s.match?(BUNDLER_SETUP_FEATURE) } end |
#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.
44 45 46 |
# File 'lib/ocran/runtime_environment.rb', line 44 def (path) File.(path, @pwd) end |
#find_load_path(path) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ocran/runtime_environment.rb', line 48 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 |