Class: LS4::StorageSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/ls4/service/storage.rb

Constant Summary collapse

IMPLS =
{}

Class Method Summary collapse

Class Method Details

.open!Object



73
74
75
# File 'lib/ls4/service/storage.rb', line 73

def self.open!
	select!(ConfigBus.get_storage_path)
end

.register(name, klass) ⇒ Object



44
45
46
47
# File 'lib/ls4/service/storage.rb', line 44

def self.register(name, klass)
	IMPLS[name.to_sym] = klass
	nil
end

.select!(uri) ⇒ Object



66
67
68
69
70
71
# File 'lib/ls4/service/storage.rb', line 66

def self.select!(uri)
	klass, expr = select_class(uri)
	klass.init

	StorageBus.open(expr)
end

.select_class(uri) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ls4/service/storage.rb', line 49

def self.select_class(uri)
	if m = /^(\w{1,8})\:(.*)/.match(uri)
		type = m[1].to_sym
		expr = m[2]
	else
		type = :dir
		expr = uri
	end

	klass = IMPLS[type]
	unless klass
		raise "unknown Storage type: #{type}"
	end

	return klass, expr
end