Module: UtilityFunctions::RubyLoader

Defined in:
lib/carat-dev/misc/utils.rb

Class Method Summary collapse

Class Method Details

.find_feature(feature) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
# File 'lib/carat-dev/misc/utils.rb', line 470

def find_feature( feature )
  with_ext( feature ) do |fname|
    $LOAD_PATH.each do |dir|
      path = dir + '/' + fname
      if File.file? path then
        return path
      end
    end
  end
  nil
end

.provide(feature) ⇒ Object



491
492
493
# File 'lib/carat-dev/misc/utils.rb', line 491

def provide( feature )
  $".push feature
end

.provided?(feature) ⇒ Boolean Also known as: required?

Returns:

  • (Boolean)


482
483
484
485
486
487
488
# File 'lib/carat-dev/misc/utils.rb', line 482

def provided?( feature )
  with_ext( feature ) do |fn|
    $".index fn and return true
  end
  
  false
end

.with_ext(feature) ⇒ Object



495
496
497
498
499
500
501
502
503
# File 'lib/carat-dev/misc/utils.rb', line 495

def with_ext( feature )
  if /\.(?:rb|#{Config::CONFIG['DLEXT']})\z/o === feature then
    yield feature
  else
    [ 'rb', Config::CONFIG['DLEXT'] ].each do |ext|
      yield feature + '.' + ext
    end
  end
end