Module: RVGP::Application::DescendantRegistry::ClassMethods
- Defined in:
- lib/rvgp/application/descendant_registry.rb
Overview
This module defines the parent’s class methods, which are attached to a parent class, at the time it includes the DescendantRegistry
Instance Method Summary collapse
-
#name ⇒ String
The name of this base class, after applying its to_s to :name_capture, and underscore’izing the capture.
-
#register_descendants(in_klass, with_name, opts = {}) ⇒ Object
This method is the main entrypoint for all of the descendent registry features.
Instance Method Details
#name ⇒ String
The name of this base class, after applying its to_s to :name_capture, and underscore’izing the capture
105 106 107 108 109 110 111 |
# File 'lib/rvgp/application/descendant_registry.rb', line 105 def name name_capture = superclass.descendant_registry[:name_capture] name = name_capture.match(to_s) ? ::Regexp.last_match(1) : to_s # underscorize the capture: name.scan(/[A-Z][^A-Z]*/).join('_').downcase end |
#register_descendants(in_klass, with_name, opts = {}) ⇒ Object
This method is the main entrypoint for all of the descendent registry features. This method installs a registry, into the provided namespace, given the provided options
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rvgp/application/descendant_registry.rb', line 88 def register_descendants(in_klass, with_name, opts = {}) @descendant_registry = { klass: in_klass, name: with_name, name_capture: opts.key?(:name_capture) ? opts[:name_capture] : /\A.*:(.+)\Z/ } define_singleton_method(:descendant_registry) { @descendant_registry } in_klass.instance_eval do iv_sym = "@#{with_name}".to_sym instance_variable_set iv_sym, ClassRegistry.new(opts) define_singleton_method(with_name) { instance_variable_get iv_sym } end end |