README.md in auth_strategist-0.6.0 vs README.md in auth_strategist-0.7.0

- old
+ new

@@ -1,11 +1,9 @@ [gem]: https://github.com/buszu/auth_strategist -[codeclimate]: https://codeclimate.com/github/buszu/auth_strategist/ AuthStrategist ====== -[![Code Climate](https://codeclimate.com/github/buszu/auth_strategist/badges/gpa.svg)](https://codeclimate.com/github/buszu/auth_strategist) [![Gem Version](https://badge.fury.io/rb/auth_strategist.svg)](http://badge.fury.io/rb/auth_strategist) AuthStrategist is a simple gem to define and use authorization strategies. ## Installation @@ -20,32 +18,18 @@ Generate initializer if using Rails: $ rails g auth_strategist:install -Or install it yourself as: - - $ gem install auth_strategist - ## Configuration ```ruby AuthStrategist.configure do |c| - # Set default strategy components (its attributes). - # Optional and empty by default. - c.default_strategy_components = [:application, :ref] - - # Set strategies directory + # Set strategies directory and load them # Required if strategies files are not already loaded c.strategies_path = 'lib/auth_strategist/strategies' - - # Register your strategies - # Required for each strategy you have defined - c.strategies do |s| - # E.g. OwnershipAuthStrategy will be available under :ownership key - s.ownership = OwnershipAuthStrategy - end + c.load_strategies! end ``` ## Usage @@ -55,35 +39,22 @@ class OwnershipAuthStrategy include AuthStrategist::StrategyInterface define_components :user, :item - def authorize! - raise unauthorized if item.user_id != user.id + def authorized? + item.user_id != user.id end end ``` * Register it ```ruby AuthStrategist.strategies do |s| - s.ownership = OwnershipAuthStrategy + s.register :ownership, OwnershipAuthStrategy end ``` -or -```ruby -AuthStrategist.configure do |c| - c.strategies do |s| - s.ownership = OwnershipAuthStrategy - end -end -``` + ### Using strategies -* Using strategy by calling authorization Service Object -```ruby -AuthStrategist::Authorize.call strategy: :ownership, - user: current_user, - item: book -``` * Using strategy with authorize! method ```ruby class SomethingsController < ApplicationController include AuthStrategist::Authorization