README.md in usable-0.1.0 vs README.md in usable-0.2.0
- old
+ new
@@ -1,29 +1,60 @@
# Usable
Rack style mixins for Ruby objects. Mount your modules like you mean it!
```ruby
+module VersionKit
+ def save_version
+ "Saving up to #{self.class.config.max_versions} versions to #{self.class.config.table_name}"
+ end
+
+ def destroy_version
+ "Deleting versions from #{self.class.config.table_name}"
+ end
+end
+
class Model
extend Usable
-
- module Versionable
- def versions
- "Saving #{self.class.config.max_versions} versions to #{self.class.config.table_name}"
- end
+
+ usable VersionKit, only: :save_version do |config|
+ config.max_versions = 10
+ config.table_name = 'custom_versions'
end
+end
- # with options hash
- use Versionable, table_name: 'custom_versions'
+>> Model.config.table_name
+=> "custom_versions"
+>> Model.new.versions
+=> "Saving up to 10 versions to custom_versions"
+>> Model.new.destroy_version
+=> nil
+```
+You can also define a custom module within the "usable" module that defines the methods which can be configured to be
+extended or excluded. The module must be named "Spec" and be defined one level inside the namespace. For example:
- # or with block
- use Versionable do |config|
- config.max_versions = 10
+```ruby
+module VersionKit
+ module Spec
+ def version
+ "spec version included"
+ end
end
+
+ def version
+ "this version not included"
+ end
+
+ def self.included(base)
+ puts base.usable_config.available_methods[:version].bind(self).call
+ end
end
-Model.config.table_name #=> 'custom_versions'
-Model.new.versions #=> "Saving 10 versions to custom_versions"
+>> Example = Class.new.extend Usable
+=> Example
+>> Example.usable VersionKit
+spec version included
+=> Example
```
## Installation
Add this line to your application's Gemfile: