Project

logcabin

0.0
No release in over 3 years
Low commit activity in last 3 years
Support dynamic loading of modules at runtime
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 0.1.1
~> 2.2.0
~> 11.2.0
~> 3.5.0
~> 0.42.0
 Project Readme

logcabin

Gem Version GitHub Workflow Status MIT Licensed

Support dynamic loading of modules at runtime

Usage

Create a collection of modules with collection = LogCabin.new(load_path: '/path/to/modules').

You can also pass in an array of paths as load_path.

You can then load a module and return it with collection.find(:module_name) (you can use a string or symbol for the name).

Modules should be children of LogCabin::Modules, like so:

module LogCabin
  module Modules
    module MyDynamicModule
      def useful_function
        puts "Hello world"
      end
    end
  end
end

This should go in the file "my_dynamic_module.rb", and would be loaded with collection.find(:my_dynamic_module). This naming convention is required for modules, where an underscore in the filename matches with a capitalized letter in the module definition.

As an example usage, you can use LogCabin to dynamically extend instances of a class:

COLLECTION = LogCabin.new(load_path: '/path/to/my/dynamic/module')

class BoringClass
  def initialize(cool_module)
    extend COLLECTION.find(cool_module)
  end
end

x = BoringClass.new('my_dynamic_module')
x.useful_function >> puts "Hello World"

Installation

gem install logcabin

License

logcabin is released under the MIT License. See the bundled LICENSE file for details.