README.md in usable-1.4.0 vs README.md in usable-2.0.0
- old
+ new
@@ -1,31 +1,35 @@
# Usable [![Gem Version](https://badge.fury.io/rb/usable.svg)](http://badge.fury.io/rb/usable) [![Build Status](https://travis-ci.org/ridiculous/usable.svg)](https://travis-ci.org/ridiculous/usable) [![Code Climate](https://codeclimate.com/github/ridiculous/usable/badges/gpa.svg)](https://codeclimate.com/github/ridiculous/usable)
-An elegant way to mount and configure your modules. Usable gives you control over which methods are included, and a simple
-interface to help you call dynamic methods with confidence.
+Usable provides an elegant way to mount and configure your modules. Class level settings can be configured on a per module basis,
+available to both the module and including class. Allows you to include only the methods you want.
```ruby
module VersionMixin
+ extend Usable
+ usables[:max_versions] = 25
+ usables[:table_name] = 'versions'
+
def save_version
- "Saving up to #{self.class.usable_config.max_versions} versions to #{self.class.usable_config.table_name}"
+ "Saving up to #{usables.max_versions} versions to #{usables.table_name}"
end
def destroy_version
- "Deleting versions from #{self.class.usable_config.table_name}"
+ "Deleting versions from #{usables.table_name}"
end
end
class Model
extend Usable
- usable VersionMixin, only: :save_version do |config|
- config.max_versions = 10
- config.table_name = 'custom_versions'
+ usable VersionMixin, only: :save_version do
+ max_versions 10
+ table_name 'custom_versions'
end
def save
- self.class.usable_method(self, :save_version).call
+ usable_method(:save_version).call
end
end
model = Model.new
model.save_version # => "Saving up to 10 versions to custom_versions"
@@ -36,28 +40,29 @@
```ruby
Model.usable VersionMixin, method: :prepend
```
-Usable reserves the `:only` and `:method` keys. All other keys in the given hash are defined as config settings.
-If you really want to define a config on the target class with one of these names, you can simply define them in the block:
+Usable reserves the `:only` and `:method` keys. All other keys in the given hash are defined as config settings. If you really
+want to define a config on the target class with one of these names, you can simply define them in the block:
```ruby
Model.usable VersionMixin, only: [:save_version] do |config|
config.only = "Will be set on `Model.usable_config.only`"
end
```
## Confidently calling methods
We should all be writing [confident code](http://www.confidentruby.com/), which is why you might want to call configurable
-methods through the `usable_method` class level function. Methods passed in with the `:only` option
+methods through the `usable_method` class and instance method. Methods passed in with the `:only` option
will _always_ return `nil` when called. Thus, the confidence.
Here's the same example as above, rewritten to call methods through the Usable interface:
```ruby
Model.usable_method(model, :save_version).call # => "Saving up to 10 versions to custom_versions"
+model.usable_method(:save_version).call # => "Saving up to 10 versions to custom_versions"
Model.usable_method(model, :destroy_version).call # => nil
```
## Module Naming Conventions