Skip to content

Commit

Permalink
let declarative_authorization support using multi auth rule files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Chen authored and stffn committed Dec 27, 2009
1 parent 0f0cd10 commit ec9d6d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -241,7 +241,7 @@ the conditions for manual rewrites.

== Authorization Rules

Authorization rules are defined in config/authorization_rules.rb. E.g.
Authorization rules are defined in config/authorization_rules.rb(Or redefine rules files path via +AUTH_RULE_FILES+). E.g.

authorization do
role :admin do
Expand Down
4 changes: 2 additions & 2 deletions lib/declarative_authorization/authorization.rb
Expand Up @@ -20,7 +20,7 @@ class AuthorizationUsageError < AuthorizationError ; end
# The exception is raised to ensure that the entire rule is invalidated.
class NilAttributeValueError < AuthorizationError; end

AUTH_DSL_FILE = "#{RAILS_ROOT}/config/authorization_rules.rb"
AUTH_DSL_FILES = ["#{RAILS_ROOT}/config/authorization_rules.rb"] unless defined? AUTH_DSL_FILES

# Controller-independent method for retrieving the current user.
# Needed for model security where the current controller is not available.
Expand Down Expand Up @@ -67,7 +67,7 @@ class Engine
def initialize (reader = nil)
if reader.nil?
begin
reader = Reader::DSLReader.load(AUTH_DSL_FILE)
reader = Reader::DSLReader.load(AUTH_DSL_FILES)
rescue SystemCallError
reader = Reader::DSLReader.new
end
Expand Down
6 changes: 4 additions & 2 deletions lib/declarative_authorization/reader.rb
Expand Up @@ -66,10 +66,12 @@ def parse (dsl_data, file_name = nil)
end

# Loads and parses a DSL from the given file name.
def self.load (dsl_file)
def self.load (dsl_files)
# TODO cache reader in production mode?
reader = new
reader.parse(File.read(dsl_file), dsl_file)
dsl_files.each do |file|
reader.parse(File.read(file), file) if File.exist?(file)
end
reader
end

Expand Down

0 comments on commit ec9d6d4

Please sign in to comment.