Sha256: f996eb0989734ae20948811ca7d81343b943cc1dec16040e04daa9a5bc2233ca
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
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 rescue NameError => e raise Authority::NoAuthorizerError.new("#{authorizer_name} does not exist in your application") 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.9.0 | lib/authority/abilities.rb |