Module: Alki::Loader

Defined in:
lib/alki/loader.rb,
lib/alki/loader/entry.rb,
lib/alki/loader/version.rb,
lib/alki/loader/registry.rb

Defined Under Namespace

Classes: Entry, Registry

Constant Summary collapse

LoaderError =
Class.new(StandardError)
VERSION =
"0.2.5"

Class Method Summary collapse

Class Method Details

.build(path, builder = nil, data = nil, &blk) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/alki/loader.rb', line 27

def self.build(path,builder=nil,data=nil,&blk)
  entry = @registry.lookup_path(path)
  unless entry
    raise LoaderError.new("No path registered for #{path}")
  end
  builder ||= entry.data[:builder]
  unless builder
    raise LoaderError.new("No builder registered for #{path}")
  end
  name = path_name(entry, path) or
    raise LoaderError.new("Path not registered with name or in $LOAD_PATH #{path}")
  data ||= entry.data
  builder = Alki::Support.load builder
  builder.build data.merge(name: name, constant_name: Alki::Support.classify(name)), &blk
end

.lookup_name(path) ⇒ Object



23
24
25
# File 'lib/alki/loader.rb', line 23

def self.lookup_name(path)
  path_name @registry.lookup_path(path), path
end

.register(path, **data) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/alki/loader.rb', line 43

def self.register(path,**data)
  unless path.start_with? '/'
    caller_dir = File.dirname(caller_locations(1,1)[0].absolute_path)
    path = File.expand_path(path,caller_dir)
  end
  @registry.add Entry.new(path,data)
end

.registered_pathsObject



12
13
14
# File 'lib/alki/loader.rb', line 12

def self.registered_paths
  @registry.paths
end

.translate(name) ⇒ Object



16
17
18
19
20
21
# File 'lib/alki/loader.rb', line 16

def self.translate(name)
  entry = @registry.lookup_name(name)
  if entry
    entry.path + name[entry.name.size..-1]
  end
end