Class: Axn::Internal::Registry
- Inherits:
-
Object
- Object
- Axn::Internal::Registry
show all
- Defined in:
- lib/axn/internal/registry.rb
Defined Under Namespace
Classes: DuplicateError, NotFound
Class Method Summary
collapse
Class Method Details
.all ⇒ Object
43
44
45
|
# File 'lib/axn/internal/registry.rb', line 43
def all
@items ||= built_in.dup
end
|
.built_in ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/axn/internal/registry.rb', line 12
def built_in
@built_in ||= begin
dir_name = name.split("::").last.underscore
files = ::Dir[File.join(registry_directory, dir_name, "*.rb")]
files.each { |file| require file }
constants = self.constants.map { |const| const_get(const) }
items = select_constants_to_load(constants)
items.to_h do |item|
name = item.name.split("::").last
key = name.underscore.to_sym
[key, item]
end
end
end
|
.clear! ⇒ Object
47
48
49
|
# File 'lib/axn/internal/registry.rb', line 47
def clear!
@items = built_in.dup
end
|
.find(name) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/axn/internal/registry.rb', line 51
def find(name)
raise not_found_error_class, "#{item_type} name cannot be nil" if name.nil?
raise not_found_error_class, "#{item_type} name cannot be empty" if name.to_s.strip.empty?
all[name.to_sym] or raise not_found_error_class, "#{item_type} '#{name}' not found"
end
|
.register(name, item) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/axn/internal/registry.rb', line 34
def register(name, item)
items = all key = name.to_sym
raise duplicate_error_class, "#{item_type} #{name} already registered" if items.key?(key)
items[key] = item
items
end
|