Sha256: 677e728867033a0216295a7c32b09a80a18aa8fb161b38d18e681441b1267088

Contents?: true

Size: 970 Bytes

Versions: 1

Compression:

Stored size: 970 Bytes

Contents

module Authority
  module Abilities
    extend ActiveSupport::Concern

    included do
      class_attribute :authorizer_name

      self.authorizer_name = "#{name}Authorizer"
    end

    module ClassMethods

      Authority.adjectives.each do |adjective|

        # Metaprogram needed methods, allowing for nice backtraces
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def #{adjective}_by?(user)
            authorizer.#{adjective}_by?(user)
          end
        RUBY
      end

      def authorizer
        @authorizer ||= authorizer_name.constantize
      end
    end

      Authority.adjectives.each do |adjective|

        # Metaprogram needed methods, allowing for nice backtraces
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def #{adjective}_by?(user)
            authorizer.#{adjective}_by?(user)
          end

          def authorizer
            self.class.authorizer.new(self)
          end
        RUBY
      end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authority-0.2.0 lib/authority/abilities.rb