Class: RailsForge::Plugins::PluginLoader
- Inherits:
-
Object
- Object
- RailsForge::Plugins::PluginLoader
- Defined in:
- lib/railsforge/plugins/plugin_loader.rb
Overview
PluginLoader manages RailsForge plugins
Constant Summary collapse
- PLUGINS_DIR =
File.('../../plugins', __FILE__)
Class Method Summary collapse
-
.create(plugin_name) ⇒ Object
Create a new plugin.
-
.list ⇒ Object
List available plugins.
-
.load(plugin_name) ⇒ Object
Load a plugin.
-
.load_all ⇒ Object
Load all plugins.
Class Method Details
.create(plugin_name) ⇒ Object
Create a new plugin
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/railsforge/plugins/plugin_loader.rb', line 41 def self.create(plugin_name) FileUtils.mkdir_p(PLUGINS_DIR) path = File.join(PLUGINS_DIR, "#{plugin_name}.rb") return if File.exist?(path) File.write(path, <<~RUBY) module RailsForge module #{plugin_name.split('_').map(&:capitalize).join} PLUGIN_NAME = "#{plugin_name}" VERSION = "0.1.0" end end RUBY puts "Created #{path}" end |
.list ⇒ Object
List available plugins
13 14 15 16 17 18 19 |
# File 'lib/railsforge/plugins/plugin_loader.rb', line 13 def self.list return [] unless Dir.exist?(PLUGINS_DIR) Dir.glob(File.join(PLUGINS_DIR, "*.rb")).map do |file| File.basename(file, ".rb") end end |
.load(plugin_name) ⇒ Object
Load a plugin
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/railsforge/plugins/plugin_loader.rb', line 22 def self.load(plugin_name) plugin_path = File.join(PLUGINS_DIR, "#{plugin_name}.rb") unless File.exist?(plugin_path) puts "Plugin '#{plugin_name}' not found" return false end require plugin_path puts "Plugin '#{plugin_name}' loaded" true end |
.load_all ⇒ Object
Load all plugins
36 37 38 |
# File 'lib/railsforge/plugins/plugin_loader.rb', line 36 def self.load_all list.each { |plugin| load(plugin) } end |