summaryrefslogtreecommitdiffhomepage
path: root/lib/felflame/component_manager.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-01-03 06:20:55 -0500
committerrealtradam <[email protected]>2022-01-03 06:20:55 -0500
commit809028c3d89993b2bb0651076ba723c11734cf3c (patch)
tree5d167f9314ed4334f02842f1a73204168d57302a /lib/felflame/component_manager.rb
parentacf82d111953f9b0a99f6870c0de31ec20c6d21b (diff)
downloadFelECS-809028c3d89993b2bb0651076ba723c11734cf3c.tar.gz
FelECS-809028c3d89993b2bb0651076ba723c11734cf3c.zip
.
Diffstat (limited to 'lib/felflame/component_manager.rb')
-rw-r--r--lib/felflame/component_manager.rb53
1 files changed, 50 insertions, 3 deletions
diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb
index ca5be89..d015d99 100644
--- a/lib/felflame/component_manager.rb
+++ b/lib/felflame/component_manager.rb
@@ -22,6 +22,7 @@ module FelFlame
const_set(component_name, Class.new(FelFlame::ComponentManager) {})
+ update_const_cache
attrs.each do |attr|
if FelFlame::Components.const_get(component_name).method_defined?("#{attr}") || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
@@ -48,8 +49,51 @@ module FelFlame
# Makes component module behave like an array of component
# managers with additional methods for managing the array
# @!visibility private
+ ##def respond_to_missing?(method, *)
+ # if constants.respond_to? method
+ # true
+ # else
+ # super
+ # end
+ #end
+
+ ## Makes component module behave like arrays with additional
+ ## methods for managing the array
+ ## @!visibility private
+ #def method_missing(method, *args, **kwargs, &block)
+ # if constants.respond_to? method
+ # constants.send(method, *args, **kwargs, &block)
+ # else
+ # super
+ # end
+ #end
+
+ # Stores the components managers in {FelFlame::Components}. This
+ # is needed because calling `FelFlame::Components.constants`
+ # will not let you iterate over the value of the constants
+ # but will instead give you an array of symbols. This caches
+ # the convertion of those symbols to the actual value of the
+ # constants
+ # @!visibility private
+ def const_cache
+ @const_cache || update_const_cache
+ end
+
+ # Updates the array that stores the constants.
+ # Used internally by FelFlame
+ # @!visibility private
+ def update_const_cache
+ @const_cache = self.constants.map do |constant|
+ self.const_get constant
+ end
+ end
+
+ # Forwards undefined methods to the array of constants
+ # if the array can handle the request. Otherwise tells
+ # the programmer their code errored
+ # @!visibility private
def respond_to_missing?(method, *)
- if constants.respond_to? method
+ if const_cache.respond_to? method
true
else
super
@@ -60,12 +104,15 @@ module FelFlame
# methods for managing the array
# @!visibility private
def method_missing(method, *args, **kwargs, &block)
- if constants.respond_to? method
- constants.send(method, *args, **kwargs, &block)
+ if const_cache.respond_to? method
+ const_cache.send(method, *args, **kwargs, &block)
else
super
end
end
+
+
+
end
end