Permalink
Browse files

add in rule reloading in development based on modified time stamps

  • Loading branch information...
1 parent 2a07f2a commit a5e6beac067e8339c73b76498a4fa817ba786ba6 @urkle urkle committed Feb 2, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 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

0 comments on commit a5e6bea

Please sign in to comment.