Project

General

Profile

Feature #12639 ยป feature_loaded.patch

segiddins (Samuel Giddins), 07/31/2016 01:04 AM

View differences:

lib/rubygems/core_ext/kernel_require.rb
22 22
    private :gem_original_require
23 23
  end
24 24

  
25
  if defined?(loaded_feature?)
26
    def gem_loaded_feature?(path)
27
      loaded_feature?(path)
28
    end
29
  else
30
    def gem_loaded_feature?(path)
31
      false
32
    end
33
  end
34
  private :gem_loaded_feature?
35

  
25 36
  ##
26 37
  # When RubyGems is required, Kernel#require is replaced with our own which
27 38
  # is capable of loading gems on demand.
......
37 48
  # that file has already been loaded is preserved.
38 49

  
39 50
  def require path
40
    RUBYGEMS_ACTIVATION_MONITOR.enter
41

  
42 51
    path = path.to_path if path.respond_to? :to_path
52
    return false if gem_loaded_feature?(path)
53

  
54
    RUBYGEMS_ACTIVATION_MONITOR.enter
43 55

  
44 56
    spec = Gem.find_unresolved_default_spec(path)
45 57
    if spec
......
138 150
  private :require
139 151

  
140 152
end
141

  
load.c
524 524
    return rb_feature_provided(feature, 0);
525 525
}
526 526

  
527
VALUE
528
rb_f_loaded_feature(VALUE obj, VALUE fname)
529
{
530
  return rb_provided(RSTRING_PTR(rb_str_encode_ospath(fname))) ? Qtrue : Qfalse;
531
}
532

  
527 533
int
528 534
rb_feature_provided(const char *feature, const char **loading)
529 535
{
......
1202 1208
    rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1);
1203 1209
    rb_define_global_function("autoload", rb_f_autoload, 2);
1204 1210
    rb_define_global_function("autoload?", rb_f_autoload_p, 1);
1211
    rb_define_global_function("loaded_feature?", rb_f_loaded_feature, 1);
1205 1212

  
1206 1213
    ruby_dln_librefs = rb_ary_tmp_new(0);
1207 1214
    rb_gc_register_mark_object(ruby_dln_librefs);