Module: Finder::Find::Roll
- Includes:
- Base
- Defined in:
- lib/finder/roll.rb
Overview
Finder methods for ‘Library` system.
Instance Method Summary collapse
-
#data_path(match, options = {}) ⇒ Object
Search project’s data paths.
-
#load_path(match, options = {}) ⇒ Array<String>
Search Roll system for current or latest library files.
-
#path(match, options = {}) ⇒ Array<String>
Search for current or latest files within a library.
Methods included from Base
#append_extensions, #feature, included, #valid_load_options
Instance Method Details
#data_path(match, options = {}) ⇒ Object
Search project’s data paths.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/finder/roll.rb', line 133 def data_path(match, ={}) return [] unless defined?(::Library) if from = [:from] ledger = {from.to_s => ::Library.ledger[from.to_s]} else ledger = ::Library.ledger end criteria = [[:version]].compact matches = [] ledger.each do |name, lib| list = [] if Array === lib lib = lib.select do |l| criteria.all?{ |c| l.version.satisfy?(c) } end lib = lib.sort.first else next unless criteria.all?{ |c| l.version.satisfy?(c) } end find = File.join(lib.location, 'data', match) list = Dir.glob(find) list = list.map{ |d| d.chomp('/') } matches.concat(list) # activate the library if activate flag lib.activate if [:activate] && !list.empty? end matches end |
#load_path(match, options = {}) ⇒ Array<String>
Search Roll system for current or latest library files. This is useful for plugin loading.
This only searches activated libraries or the most recent version of any given library.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/finder/roll.rb', line 71 def load_path(match, ={}) return [] unless defined?(::Library) = () if from = [:from] libs = ::Library.ledger[from.to_s] if libs case libs when ::Array ledger = libs.empty? ? {} : {from.to_s => libs} else ledger = {from.to_s => libs} end else ledger = {} end else ledger = ::Library.ledger end criteria = [[:version]].compact matches = [] ledger.each do |name, lib| list = [] if Array===lib lib = lib.select do |l| criteria.all?{ |c| l.version.satisfy?(c) } end lib = lib.sort.first else next unless criteria.all?{ |c| lib.version.satisfy?(c) } end lib.loadpath.each do |path| find = File.join(lib.location, path, match) list = Dir.glob(find) list = list.map{ |d| d.chomp('/') } # return relative load path unless absolute flag if [:relative] # the extra '' in File.join adds a '/' to the end of the path list = list.map{ |f| f.sub(File.join(lib.location, path, ''), '') } end matches.concat(list) end # activate the library if activate flag lib.activate if [:activate] && !list.empty? end matches end |
#path(match, options = {}) ⇒ Array<String>
Search for current or latest files within a library.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/finder/roll.rb', line 20 def path(match, ={}) return [] unless defined?(::Library) if from = [:from] ledger = {from.to_s => ::Library.ledger[from.to_s]} else ledger = ::Library.ledger end criteria = [[:version]].compact matches = [] ledger.each do |name, lib| if Array === lib lib = lib.select do |l| criteria.all?{ |c| l.version.satisfy?(c) } end lib = lib.sort.first else next unless criteria.all?{ |c| lib.version.satisfy?(c) } end find = File.join(lib.location, match) list = Dir.glob(find) list = list.map{ |d| d.chomp('/') } matches.concat(list) end matches end |