RubyGems Navigation menu

pluggability 0.4.2

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 < Driver ...implementation... end and another that outputs plain ascii text: #mygem/drivers/ascii.rb: require 'mygem/driver' unless defined?( MyGem::Driver ) class MyGem::Driver::ASCII < Driver ...implementation... end Now the driver is configurable by the end-user, who can just set it by its short name: require 'mygem' config[:driver_type] #=> "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 )

Gemfile:
= 复制到剪贴板 已复制!

安装:
=

版本列表:

  1. 0.9.0 - June 08, 2023 (18.0 KB)
  2. 0.8.0 - December 01, 2022 (18.0 KB)
  3. 0.7.0 - February 05, 2020 (23.5 KB)
  4. 0.6.0 - March 21, 2018 (25.0 KB)
  5. 0.5.0 - January 19, 2018 (25.0 KB)
  6. 0.4.2 - March 04, 2015 (24.0 KB)
显示所有版本 (共 14 个)

Runtime 依赖 (1):

loggability ~> 0.8

Development 依赖 (6):

hoe ~> 3.13
hoe-bundler ~> 1.2
hoe-deveiate ~> 0.6
hoe-highline ~> 0.2
hoe-mercurial ~> 1.4
rdoc ~> 4.0

业主:

作者:

  • Martin Chase, Michael Granger

SHA 256 校验和:

72cceb77273b627f98d0990e1f06e67e180a848168113db74465d1f98ba755ec

下载总量 43,100

这个版本 2,140

许可:

BSD

需要的 Ruby 版本: >= 0

需要的 RubyGems 版本: ~> 2.1

链接: