Module: Trax::Core::EagerAutoloadNamespace
- Defined in:
- lib/trax/core/eager_autoload_namespace.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #autoload_class_names ⇒ Object
- #autoload_file_paths ⇒ Object
- #eager_autoload_filepath ⇒ Object
- #module_path ⇒ Object
Class Method Details
.extended(base) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/trax/core/eager_autoload_namespace.rb', line 5 def self.extended(base) source_file_path = caller[0].partition(":")[0] base.module_eval do @eager_autoload_filepath = source_file_path end end |
Instance Method Details
#all ⇒ Object
13 14 15 16 17 |
# File 'lib/trax/core/eager_autoload_namespace.rb', line 13 def all @all ||= autoload_class_names.map do |klass| const_get(:"#{klass}") end end |
#autoload_class_names ⇒ Object
23 24 25 26 27 |
# File 'lib/trax/core/eager_autoload_namespace.rb', line 23 def autoload_class_names @autoload_class_names = autoload_file_paths.map do |path| ::File.basename(path.to_s).split(".rb").shift.try(:classify) end end |
#autoload_file_paths ⇒ Object
19 20 21 |
# File 'lib/trax/core/eager_autoload_namespace.rb', line 19 def autoload_file_paths @autoload_file_paths = ::Dir[module_path.join('*.rb')] end |
#eager_autoload_filepath ⇒ Object
29 30 31 |
# File 'lib/trax/core/eager_autoload_namespace.rb', line 29 def eager_autoload_filepath @eager_autoload_filepath end |
#module_path ⇒ Object
33 34 35 |
# File 'lib/trax/core/eager_autoload_namespace.rb', line 33 def module_path @module_path ||= ::Pathname.new(::File.path(eager_autoload_filepath).gsub(".rb", "")) end |