# 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) 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 config.max_versions = 25 config.table_name = 'versions' def save_version "Saving #{usables.max_versions} #{usables.table_name}" end def destroy_version "Deleting versions from #{usables.table_name}" end end class Model extend Usable usable VersionMixin, only: :save_version do max_versions 10 end def save save_version end end model = Model.new model.save_version # => "Saving 10 versions" model.destroy_version # => NoMethodError: undefined method `destroy_version' for # 'Hawaii' Model.usables.census[:daily_visitors] # => 218150 ``` ## 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 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 Modules with the following names found within the target module's namespace will be automatically used. * `ClassMethods` * `InstanceMethods` ## Notes If the given module is modified by the `:only` option, then Usable will duplicate the module so that it doesn't mutate it globally. Duplicating a module returns an anonymous module. But anonymous mods in the ancestor list can be confusing. So Usable gives the modified module a name, which is the same name as the original module but with "Used" appended. ```ruby Mixin => MixinUsed ``` ## Installation Add this line to your application's Gemfile: ```ruby gem 'usable' ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/ridiculous/usable.