Class: Anyway::Loaders::Registry
- Inherits:
-
Object
- Object
- Anyway::Loaders::Registry
- Defined in:
- lib/anyway/loaders.rb,
sig/anyway_config.rbs
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #append(id, handler = nil) {|arg0| ... } ⇒ Object
- #delete(id) ⇒ void
- #each(&block) ⇒ Object
- #freeze ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #insert_after(another_id, id, handler = nil) {|arg0| ... } ⇒ Object
- #insert_before(another_id, id, handler = nil) {|arg0| ... } ⇒ Object
- #keys ⇒ Array[Symbol]
- #override(id, handler) {|arg0| ... } ⇒ Object
- #prepend(id, handler = nil) {|arg0| ... } ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
15 16 17 |
# File 'lib/anyway/loaders.rb', line 15 def initialize @registry = [] end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/anyway/loaders.rb', line 13 def registry @registry end |
Instance Method Details
#append(id, loader) ⇒ void #append(id) ⇒ void
24 25 26 27 |
# File 'lib/anyway/loaders.rb', line 24 def append(id, handler = nil, &block) handler ||= block insert_at(registry.size, id, handler) end |
#delete(id) ⇒ void
This method returns an undefined value.
52 53 54 55 56 57 |
# File 'lib/anyway/loaders.rb', line 52 def delete(id) find(id).then do |id_to_handler| raise ArgumentError, "Loader with ID #{id} hasn't been registered" if id_to_handler.nil? registry.delete id_to_handler end end |
#each(&block) ⇒ Object
59 60 61 |
# File 'lib/anyway/loaders.rb', line 59 def each(&block) registry.each(&block) end |
#freeze ⇒ Object
65 |
# File 'lib/anyway/loaders.rb', line 65 def freeze() = registry.freeze |
#insert_after(another_id, id, loader) ⇒ void #insert_after(another_id, id) ⇒ void
37 38 39 40 41 42 43 |
# File 'lib/anyway/loaders.rb', line 37 def insert_after(another_id, id, handler = nil, &block) ind = registry.find_index { |(hid, _)| hid == another_id } raise ArgumentError, "Loader with ID #{another_id} hasn't been registered" if ind.nil? handler ||= block insert_at(ind + 1, id, handler) end |
#insert_before(another_id, id, loader) ⇒ void #insert_before(another_id, id) ⇒ void
29 30 31 32 33 34 35 |
# File 'lib/anyway/loaders.rb', line 29 def insert_before(another_id, id, handler = nil, &block) ind = registry.find_index { |(hid, _)| hid == another_id } raise ArgumentError, "Loader with ID #{another_id} hasn't been registered" if ind.nil? handler ||= block insert_at(ind, id, handler) end |
#keys ⇒ Array[Symbol]
63 |
# File 'lib/anyway/loaders.rb', line 63 def keys() = registry.map(&:first) |
#override(id, loader) ⇒ void #override(id) ⇒ void
45 46 47 48 49 50 |
# File 'lib/anyway/loaders.rb', line 45 def override(id, handler) find(id).then do |id_to_handler| raise ArgumentError, "Loader with ID #{id} hasn't been registered" if id_to_handler.nil? id_to_handler[1] = handler end end |
#prepend(id, loader) ⇒ void #prepend(id) ⇒ void
19 20 21 22 |
# File 'lib/anyway/loaders.rb', line 19 def prepend(id, handler = nil, &block) handler ||= block insert_at(0, id, handler) end |