class Datafile::FileDatasetRegistry
Public Class Methods
new()
click to toggle source
# File lib/datafile/workers/file/registry.rb, line 10 def initialize ## org rootpaths @roots = {} ## org defaults (use merge to overwrite for now) @roots[:openmundi] = '../../openmundi' ## OPENMUNDI_ROOT = "../../openmundi" @roots[:openfootball] = '..' ## OPENFOOTBALL_ROOT = ".." @roots[:openbeer] = '..' @roots[:footballcsv] = '..' end
Public Instance Methods
lookup( name )
click to toggle source
# File lib/datafile/workers/file/registry.rb, line 27 def lookup( name ) path, _ = lookup_path( name ) ## note: ignore error message passed along in return path end
lookup!( name )
click to toggle source
# File lib/datafile/workers/file/registry.rb, line 32 def lookup!( name ) path, error = lookup_path( name ) raise error if error path end
merge( hash )
click to toggle source
# File lib/datafile/workers/file/registry.rb, line 21 def merge( hash ) ## todo: add support for merging project mappings too ## use merge_roots and merge_projects ?? why, why not?? @roots = @roots.merge( hash ) end
Private Instance Methods
lookup_path( name )
click to toggle source
# File lib/datafile/workers/file/registry.rb, line 40 def lookup_path( name ) ## split name in org/user + project (e.g. openfootball/at-austria) parts = name.split( '/' ) ## check/todo: assert parts == 2 -- why, why not?? root = @roots[ parts[0].to_sym ] if root.nil? msg = "no mapping found for '#{parts[0]}' in '#{name}'" logger.error( msg ) return [nil, DatasetNotFoundError.new( msg )] ## throw exception FileNotFound / DatasetNotFound ?? end path = "#{root}/#{parts[1]}" ## check if folder/directory exists unless File.exist?( path ) msg = "no file found for '#{name}'; expected '#{path}'" logger.error( msg ) return [nil, DatasetNotFoundError.new( msg )] ## throw exception FileNotFound / DatasetNotFound ?? end ### check for File.directory?( path ) too - why, why not??? [path, nil] ## use go-style returns with error as second argument (as error as value) end