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.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/m365_active_storage/files.rb', line 55 def self.controller_classes controller_files.map do |path| # Extract the relative path from the gem root, then convert to class name root_path = Pathname.new("#{root}/lib") file_path = Pathname.new(path) # Skip files that are not within the gem's lib directory (e.g., from other gem installations) next nil if file_path.relative_path_from(root_path).to_s.start_with?("..") relative_path = file_path.relative_path_from(root_path).to_s class_name = relative_path.remove("controllers/").remove(".rb").camelize.constantize class_name end.compact 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.
38 39 40 |
# File 'lib/m365_active_storage/files.rb', line 38 def self.controller_files Gem.find_files("m365_active_storage/controllers/**/*.rb") end |