Class: M365ActiveStorage::Files
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- M365ActiveStorage::Files
- Defined in:
- lib/m365_active_storage/files.rb
Overview
File Discovery and Loading
Utilities for discovering and loading controller and helper files from the gem.
Responsibilities
-
Discover controller files from the gem installation
-
Load controller classes into memory
-
Provide convenient accessors for gem resources
Architecture
This class uses Gem.find_files to locate all controller files within the installed gem. This allows the gem to dynamically load controllers without hardcoding file paths.
Example Usage
files = M365ActiveStorage::Files.controller_files
classes = M365ActiveStorage::Files.controller_classes
Class Method Summary collapse
-
.controller_classes ⇒ Array<Class>
Get all controller classes from the gem.
-
.controller_files ⇒ Array<String>
Get all controller file paths from the gem.
Class Method Details
.controller_classes ⇒ Array<Class>
Get all controller classes from the gem
Loads and returns the constantized controller class objects. First discovers files via #controller_files, then converts file paths to class names and loads them.
53 54 55 56 57 |
# File 'lib/m365_active_storage/files.rb', line 53 def self.controller_classes controller_files.map do |path| path.remove("#{root}/lib/").remove("controllers/").remove(".rb").camelize.constantize end end |
.controller_files ⇒ Array<String>
Get all controller file paths from the gem
Searches the installed gem for all Ruby files in the controllers directory. Uses Gem.find_files to locate files regardless of gem installation method.
36 37 38 |
# File 'lib/m365_active_storage/files.rb', line 36 def self.controller_files Gem.find_files("m365_active_storage/controllers/**/*.rb") end |