RubyGems Navigation menu

pluggability 0.1.0

Pluggability is a mixin module that turns an including class into a factory for its derivatives, capable of searching for and loading them by name. This is useful when you have an abstract base class which defines an interface and basic functionality for a part of a larger system, and a collection of subclasses which implement the interface for different underlying functionality. An example of where this might be useful is in a program which generates output with a 'driver' object, which provides a unified interface but generates different kinds of output. First the abstract base class, which is extended with Pluggability: # in mygem/driver.rb: require 'pluggability' require 'mygem' unless defined?( MyGem ) class MyGem::Driver extend Pluggability plugin_prefixes "drivers", "drivers/compat" end We can have one driver that outputs PDF documents: # mygem/drivers/pdf.rb: require 'mygem/driver' unless defined?( MyGem::Driver ) class MyGem::Driver::PDF "pdf" driver = MyGem::Driver.create( config[:driver_type] ) driver.class #=> MyGem::Driver::PDF # You can also pass arguments to the constructor, too: ascii_driver = MyGem::Driver.create( :ascii, :columns => 80 )

Versions:

  1. 0.4.3 - March 4, 2015 (24 KB)
  2. 0.4.2 - March 4, 2015 (24 KB)
  3. 0.4.0 - January 8, 2014 (22.5 KB)
  4. 0.3.0 - September 26, 2013 (22.5 KB)
  5. 0.2.0 - March 28, 2013 (21.5 KB)
Show all versions (9 total)

Runtime Dependencies:

Authors:

  • Martin Chase, Michael Granger

Owners:

04cdb622ce0aac272b61f23f373e2abf

Sha 256 checksum:

39de3f98dce35eba57448b9402f20f15acdd8de59629ab6f8c47fbc2d12a0a8d

Total downloads 6,797

For this version 792

Show all versions (9 total)

Required Ruby Version: None

License:

BSD

Gemfile:
= Copy to clipboard Copied!

install:
= Copy to clipboard Copied!

Links: