lib/cantango/permission_engine/yaml_store.rb in cantango-0.9.3.2 vs lib/cantango/permission_engine/yaml_store.rb in cantango-0.9.4

- old
+ new

@@ -1,30 +1,41 @@ require 'yaml' module CanTango class PermissionEngine < Engine class YamlStore < Store - attr_reader :path + attr_reader :path, :last_load_time # for a YamlStore, the name is the name of the yml file # options: extension, path def initialize name, options = {} super end def load! loader.load! + @last_load_time = Time.now end def load_from_hash hash loader.load_from_hash hash end - # @stanislaw: don't like this, because what if loader#load! will be called - # twice during object's (YamlStore.new) life time! + # return cached permissions if file has not changed since last load + # otherwise load permissions again to reflect changes! def permissions - @permissions ||= loader.permissions + return @permissions if changed? + @permissions = loader.permissions + end + + def changed? + return true if !last_load_time + last_modify_time <= last_load_time + end + + def last_modify_time + File.mtime(file_path) end CanTango.config.permission_engine.types.each do |type| define_method(:"#{type}_permissions") do loader.send(:"#{type}_permissions") || {}