Class: SportDb::Pathspecs
- Inherits:
-
Object
- Object
- SportDb::Pathspecs
- Defined in:
- lib/fbtok/pathspec.rb
Overview
change to a module - why? why not?
Class Method Summary collapse
-
._expand_pathspecs(names) ⇒ Object
quick (internal) helper to expand names (directories) ending with /* with Pathspec.find.
- .build(args, path: [], filepack: nil) ⇒ Object
- .debug=(value) ⇒ Object
-
.debug? ⇒ Boolean
note: default is FALSE.
- .read(src) ⇒ Object
Class Method Details
._expand_pathspecs(names) ⇒ Object
quick (internal) helper to
expand names (directories) ending with /*
with Pathspec.find
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/fbtok/pathspec.rb', line 211 def self.( names ) datafiles = [] names.each do |name| if name.end_with?('/*') datafiles += Pathspec.find( name[0..-3] ) else datafiles << name end end datafiles end |
.build(args, path: [], filepack: nil) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/fbtok/pathspec.rb', line 223 def self.build( args, path: [], filepack: nil ) recs = [] ## check fo no args case (and filepack present with default) if args.empty? if filepack && filepack.has_key?('default') recs << { 'path' => '<default>', 'datafiles' => (filepack['default']) } end else ## note - collect all "loose/standalone" files (NOT directories) ## in single default pathspec node more = [] args.each do |arg| ## note - ALWAYS give priority to existing directory matches (over filepack) ## e.g. euro or such - why? why not? ## ## todo/check if euro/ works too? ## check if directory ## note - make find_dir/path lookup an env variable ## e.g. FBTXT_ROOTDIR, FBTXT_SOURCE, FBSOURCE, ## FBTXT_REPOS/PACKS/etc. or such!!! ## add dir_path/dirs or such to build - why? why not? if dir=find_dir( arg, path: ['/sports/openfootball'] ) recs << { 'path' => arg, 'datafiles' => Pathspec.find( dir ) } elsif filepack && filepack.has_key?( arg.downcase ) recs << { 'path' => "<#{arg.downcase}>", 'datafiles' => (filepack[arg.downcase]) } else ## assume it's a file file = find_file( arg, path: path ) ## check if file (exists) in any path lookup if file ## todo/fix: ## add File.expand_path upstream in find_file !!! ## and remove later here ## also fix upstream Errorno::ENOENT to Errno::ENOENT !!! ## ## make sure path exists; raise error if not ## (auto-)expand path to normalize - yes why? why not? more << File.(file) else raise Errno::ENOENT, "No such file or directory - #{arg}" end end end if more.size > 0 recs << { 'path' => '<input>', 'datafiles' => more } end end recs end |
.debug=(value) ⇒ Object
178 |
# File 'lib/fbtok/pathspec.rb', line 178 def self.debug=(value) @@debug = value; end |
.debug? ⇒ Boolean
note: default is FALSE
179 |
# File 'lib/fbtok/pathspec.rb', line 179 def self.debug?() @@debug ||= false; end |
.read(src) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/fbtok/pathspec.rb', line 182 def self.read( src ) ## note: normalize src - use File.expand_path ?? ## change all backslash to slash for now (\ to /) fullsrc = File.( src ) recs = read_csv( fullsrc ) pp recs if debug? ## note - make pathspecs relative to passed in file arg!!! basedir = File.dirname( fullsrc ) recs.each do |rec| ## ## todo/check - check for season/seasons column - why? why not? path = rec['path'] fullpath = File.( path, basedir ) datafiles = Pathspec.find( fullpath ) ## auto-add (new) datafiles column (from expanded pathspec) rec['datafiles'] = datafiles end recs end |