Module: GRI::Plugin
Instance Method Summary collapse
- #get_gem_dirs ⇒ Object
- #get_plugin_files(dir, config = nil) ⇒ Object
- #load_plugin_dir(dir, config = nil) ⇒ Object
- #load_plugins(dirs = [], config = nil) ⇒ Object
Instance Method Details
#get_gem_dirs ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gri/plugin.rb', line 51 def get_gem_dirs dirs = [] if Object.const_defined?(:Gem) if defined?(::Gem::Specification) and Gem::Specification.respond_to?(:find_all) specs = Gem::Specification.find_all {|spec| spec.require_paths.map {|path| File.directory?("#{spec.gem_dir}/#{path}/gri/plugin")}.any? }.sort_by {|spec| spec.version}.reverse names = {} specs.each {|spec| names[spec.name] ||= spec} names.values.each {|spec| dirs += spec.require_paths.map {|path| "#{spec.gem_dir}/#{path}/gri/plugin"} } elsif Gem.respond_to?(:searcher) specs = Gem.searcher.find_all 'gri/plugin/*.rb' names = {} specs.sort_by {|spec| spec.version}.reverse.each {|spec| names[spec.name] ||= spec } names.values.each {|spec| files = Gem.searcher.matching_files spec, 'gri/plugin/*.rb' dirs += files.map {|fname| File.dirname fname} } end end dirs end |
#get_plugin_files(dir, config = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gri/plugin.rb', line 30 def get_plugin_files dir, config=nil files = Dir.entries(dir).sort.select {|fname| fname =~ /\A[^.].*\.rb$/} if config if config['enable-plugin'] eps = config.getvar 'enable-plugin' files = files.select {|fname| s = fname.sub(/\.rb$/, '') eps.detect {|pname| pname == s} } end if config['disable-plugin'] dps = config.getvar 'disable-plugin' files = files.select {|fname| s = fname.sub(/\.rb$/, '') !dps.detect {|pname| pname == s} } end end files end |
#load_plugin_dir(dir, config = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gri/plugin.rb', line 11 def load_plugin_dir dir, config=nil dir = File. dir return unless File.exists? dir files = get_plugin_files dir, config files.each {|fname| unless @loaded[fname] path = File.join dir, fname begin require path Log.debug "load plugin: '#{path}'" rescue LoadError Log.debug "LoadError: #{$!}" puts "LoadError: #{$!}" if $debug end @loaded[fname] = path end } end |
#load_plugins(dirs = [], config = nil) ⇒ Object
5 6 7 8 9 |
# File 'lib/gri/plugin.rb', line 5 def load_plugins dirs=[], config=nil @loaded = {} dirs = [File.join(File.dirname(__FILE__), 'plugin')] + get_gem_dirs + dirs dirs.each {|dir| load_plugin_dir dir, config} end |