Skip to content

Instantly share code, notes, and snippets.

@anga
Last active December 11, 2015 18:48
Show Gist options
  • Save anga/4644133 to your computer and use it in GitHub Desktop.
Save anga/4644133 to your computer and use it in GitHub Desktop.
declarative_authorization macro
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