README.md in registrable-0.1.0 vs README.md in registrable-0.2.0

- old
+ new

@@ -4,48 +4,86 @@ ### Bundler: `gem "registrable"` ### RubyGems: `gem install registrable` -## Usage +## Examples +### Plugin + ```rb require 'registrable' +module Plugin + + extend Registrable + + class Base + def self.inherited(subclass) + identifier = subclass.to_s + .split('::').last + .gsub(/([a-z0-9])([A-Z])/, '\1_\2') + .downcase.to_sym + + Plugin.register(identifier, subclass) + end + end + +end + +class MyPlugin < Plugin::Base; end +class AnotherPlugin < Plugin::Base; end +``` + +```rb +p Plugin.registry.keys # => [:my_plugin, :another_plugin] +p Plugin[:my_plugin] == MyPlugin # => true +p Plugin[:another_plugin] == AnotherPlugin # => true +``` + +### Role + +```rb +require 'registrable' + class Role + + extend Registrable + def initialize(read, modify) - @read, @modify = create, modify + @read, @modify = read, modify end def read? @read end def modify? @modify end + end class User - extend Registrable def initialize(role) self.role = role end attr_reader :role def role=(role) - role = Role.registry[identifier] || Role.registry[:other] unless role.is_a?(Role) + role = Role.registry[role] || Role.registry[:other] unless role.is_a?(Role) @role = role end + end -Role.register(:other, false, false) -Role.register(:user, true, false) -Role.register(:admin, true, true) +Role.register(:other, Role.new(false, false)) +Role.register(:user, Role.new(true, false)) +Role.register(:admin, Role.new(true, true)) ``` ```rb other = User.new(:other) @@ -77,10 +115,10 @@ * `bin/rake version:bump` * `bin/rake release` to create a git tag for the version, push git commits and tags, and push the gem to [rubygems.org](https://rubygems.org). ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/RyanScottLewis/striker. +Bug reports and pull requests are welcome on GitHub at https://github.com/RyanScottLewis/registrable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License