<commit_before>= HAL. Minimalist authorization framework for Ruby

HAL is a class-based authorization framework for Ruby. It lets you define
authorization rules on classes, which will then be applied to all instances
of said classes. For example:

    class User < Struct.new(:name); end
    dave = User.new("Dave")

    HAL.rules_for User do
      def open_the_pod_bay_doors?
        subject.name != "Dave"
      end
    end

    HAL.can(dave).open_the_pod_bay_doors? #=> false

When defining rules you can access a +subject+ method, which will reference
whatever object you pass to +can+.

You also have a more powerful version of <tt>can</tt>, called <tt>can!</tt>,
which takes a block and will raise <tt>HAL::ICantLetYouDoThat</tt> if the
block evaluates to false:

    HAL.can!(dave) {|can| can.open_the_pod_bay_doors? } #=> raises!

Finally, you can include +HAL+ into your classes to get +can+ and
<tt>can!</tt> as helper methods.

    class UsersController < ApplicationController
      include HAL

      before_filter :check_permissions, :only => [:edit, :update, :destroy]

      rescue_from HAL::ICantLetYouDoThat do
        redirect_to users_url, :alert => "Sorry Dave, I can't let you do that"
      end

      def check_permissions
        can!(current_user) {|can| can.edit_user?(current_user) }
      end
    end<commit_msg>Installation instructions<commit_after>= HAL. Minimalist authorization framework for Ruby

HAL is a class-based authorization framework for Ruby. It lets you define
authorization rules on classes, which will then be applied to all instances
of said classes. For example:

    class User < Struct.new(:name); end
    dave = User.new("Dave")

    HAL.rules_for User do
      def open_the_pod_bay_doors?
        subject.name != "Dave"
      end
    end

    HAL.can(dave).open_the_pod_bay_doors? #=> false

When defining rules you can access a +subject+ method, which will reference
whatever object you pass to +can+.

You also have a more powerful version of <tt>can</tt>, called <tt>can!</tt>,
which takes a block and will raise <tt>HAL::ICantLetYouDoThat</tt> if the
block evaluates to false:

    HAL.can!(dave) {|can| can.open_the_pod_bay_doors? } #=> raises!

Finally, you can include +HAL+ into your classes to get +can+ and
<tt>can!</tt> as helper methods.

    class UsersController < ApplicationController
      include HAL

      before_filter :check_permissions, :only => [:edit, :update, :destroy]

      rescue_from HAL::ICantLetYouDoThat do
        redirect_to users_url, :alert => "Sorry Dave, I can't let you do that"
      end

      def check_permissions
        can!(current_user) {|can| can.edit_user?(current_user) }
      end
    end

== Installing

As a RubyGem

    gem install hal

For rails 2.3, add to your config/environment.rb:

    config.gem "hal", :lib => "hal/rails"

For rails 3, add to your Gemfile:

    gem "hal", :require => "hal/rails"
{'fraction_non_alphanumeric': 0.09474768280123584, 'fraction_numerical': 0.0010298661174047373, 'mean_word_length': 3.517829457364341, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3454179', 'n_tokens_mistral': 920, 'n_tokens_neox': 874, 'n_words': 327}