README.md in ddplugin-1.0.1 vs README.md in ddplugin-1.0.2

- old
+ new

@@ -1,9 +1,10 @@ -[![Build Status](https://travis-ci.org/ddfreyne/ddplugin.png)](https://travis-ci.org/ddfreyne/ddplugin) -[![Code Climate](https://codeclimate.com/github/ddfreyne/ddplugin.png)](https://codeclimate.com/github/ddfreyne/ddplugin) -[![Coverage Status](https://coveralls.io/repos/ddfreyne/ddplugin/badge.png?branch=master)](https://coveralls.io/r/ddfreyne/ddplugin) -[![Inline docs](http://inch-ci.org/github/ddfreyne/ddplugin.png)](http://inch-ci.org/github/ddfreyne/ddplugin) +[![Gem version](http://img.shields.io/gem/v/ddplugin.svg)](http://rubygems.org/gems/ddplugin) +[![Gem downloads](https://img.shields.io/gem/dt/ddplugin.svg)](http://rubygems.org/gems/ddplugin) +[![Build status](http://img.shields.io/travis/ddfreyne/ddplugin.svg)](https://travis-ci.org/ddfreyne/ddplugin) +[![Code Climate](http://img.shields.io/codeclimate/github/ddfreyne/ddplugin.svg)](https://codeclimate.com/github/ddfreyne/ddplugin) +[![Code Coverage](https://img.shields.io/coveralls/ddfreyne/ddplugin.svg)](https://coveralls.io/r/ddfreyne/ddplugin) # ddplugin *ddplugin* is a library for managing plugins. @@ -27,11 +28,11 @@ A typical way to use plugins would be to store the plugin names in a configuration file, so that the actual plugin implementations can be discovered at runtime. ## Requirements -*ddplugin* requires Ruby 2.1 or higher. +*ddplugin* requires Ruby 2.3 or higher. ## Versioning *ddplugin* adheres to [Semantic Versioning 2.0.0](http://semver.org). @@ -61,72 +62,105 @@ class DataSource extend DDPlugin::Plugin end ``` -To define a plugin, create a class that inherits from the plugin type and sets the identifier: +To define a plugin, create a class that inherits from the plugin type and sets the identifier, either as a symbol or a string: ```ruby class ERBFilter < Filter + # Specify the identifier as a symbol… identifier :erb end class HamlFilter < Filter - identifier :haml + # … or as a string … + identifier 'haml' end class FilesystemDataSource < DataSource - identifier :filesystem + # … or even provide multiple. + identifiers :filesystem, :file_system end class PostgresDataSource < DataSource - identifier :postgres + # … or mix and match (not sure why you would, though) + identifier :postgres, 'postgresql' end ``` To find a plugin of a given type and with a given identifier, call `.named` on the plugin type, passing an identifier: ```ruby Filter.named(:erb) # => ERBFilter -Filter.named(:haml) +Filter.named('haml') # => HamlFilter DataSource.named(:filesystem) # => FilesystemDataSource DataSource.named(:postgres) # => PostgresDataSource ``` +In a real-world situation, the plugin types could be described in the environment: + +``` +% cat .env +DATA_SOURCE_TYPE=postgres +``` + +```ruby +DataSource.named(ENV.fetch('DATA_SOURCE_TYPE')) +# => PostgresDataSource +``` + +… or in a configuration file: + +``` +% cat config.yml +data_source: 'filesystem' +``` + +```ruby +config = YAML.load_file('config.yml') +DataSource.named(config.fetch('data_source')) +# => FilesystemDataSource +``` + To get all plugins of a given type, call `.all` on the plugin type: ```ruby Filter.all -# => [ ERBFilter, HamlFilter ] +# => [ERBFilter, HamlFilter] DataSource.all -# => [ FilesystemDataSource, PostgresDataSource ] +# => [FilesystemDataSource, PostgresDataSource] ``` -To get the identifier of a plugin, call `.identifier`: +To get the identifier of a plugin, call `.identifier`, which returns a symbol: ```ruby Filter.named(:erb).identifier # => :erb +Filter.named('haml').identifier +# => :haml + PostgresDataSource.identifier # => :postgres ``` ## Development Pull requests and issues are greatly appreciated. When you submit a pull request, make sure that your change is covered by tests, and that the `README` and [YARD](http://yardoc.org/) source code documentation are still up-to-date. -To run the tests, execute `rake`: +To run the tests: ``` -% rake +% bundle install +% bundle exec rake ```