From a5e6beac067e8339c73b76498a4fa817ba786ba6 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Thu, 2 Feb 2012 15:59:48 -0500 Subject: [PATCH] add in rule reloading in development based on modified time stamps --- lib/declarative_authorization/authorization.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/declarative_authorization/authorization.rb b/lib/declarative_authorization/authorization.rb index b342ae36..55b8a21b 100644 --- a/lib/declarative_authorization/authorization.rb +++ b/lib/declarative_authorization/authorization.rb @@ -277,12 +277,23 @@ def roles_for (user) def roles_with_hierarchy_for(user) flatten_roles(roles_for(user)) end - + + def self.development_reload? + if Rails.env.development? + mod_time = AUTH_DSL_FILES.map { |m| File.mtime(m) }.flatten.max + @@auth_dsl_last_modified ||= mod_time + if mod_time > @@auth_dsl_last_modified + @@auth_dsl_last_modified = mod_time + return true + end + end + end + # Returns an instance of Engine, which is created if there isn't one # yet. If +dsl_file+ is given, it is passed on to Engine.new and # a new instance is always created. def self.instance (dsl_file = nil) - if dsl_file + if dsl_file or development_reload? @@instance = new(dsl_file) else @@instance ||= new