Last active
December 11, 2015 18:48
-
-
Save anga/4644133 to your computer and use it in GitHub Desktop.
declarative_authorization macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Pivilages | |
def load_privilages_for(user) | |
Authorization.current_user = user | |
file_name = File.join(Rails.root, 'config', 'authorization_rules.rb') | |
rules = File.read(file_name) | |
load_engine_analyzer_for rules | |
end | |
def permit?(*args) | |
@engine.permit?(*args) | |
end | |
private | |
def load_engine_analyzer_for(rules) | |
@reader = Authorization::Reader::DSLReader.new | |
@reader.parse rules | |
@engine = Authorization::Engine.new(@reader) | |
@analyzer = Authorization::DevelopmentSupport::Analyzer.new(@engine) | |
@analyzer.analyze @rules | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment