Class: CanTango::PermissionEngine::YamlStore
- Defined in:
- lib/cantango/permission_engine/yaml_store.rb
Instance Attribute Summary collapse
-
#last_load_time ⇒ Object
readonly
Returns the value of attribute last_load_time.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Store
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ YamlStore
constructor
for a YamlStore, the name is the name of the yml file options: extension, path.
- #last_modify_time ⇒ Object
- #load! ⇒ Object
- #load_from_hash(hash) ⇒ Object
-
#permissions ⇒ Object
return cached permissions if file has not changed since last load otherwise load permissions again to reflect changes!.
- #save!(perms = nil) ⇒ Object
- #save_permissions(perms) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ YamlStore
for a YamlStore, the name is the name of the yml file options: extension, path
11 12 13 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 11 def initialize name, = {} super end |
Instance Attribute Details
#last_load_time ⇒ Object (readonly)
Returns the value of attribute last_load_time.
6 7 8 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 6 def last_load_time @last_load_time end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 6 def path @path end |
Instance Method Details
#changed? ⇒ Boolean
31 32 33 34 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 31 def changed? return true if !last_load_time last_modify_time <= last_load_time end |
#last_modify_time ⇒ Object
36 37 38 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 36 def last_modify_time File.mtime(file_path) end |
#load! ⇒ Object
15 16 17 18 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 15 def load! loader.load! @last_load_time = Time.now end |
#load_from_hash(hash) ⇒ Object
20 21 22 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 20 def load_from_hash hash loader.load_from_hash hash end |
#permissions ⇒ Object
return cached permissions if file has not changed since last load otherwise load permissions again to reflect changes!
26 27 28 29 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 26 def return @permissions if changed? @permissions = loader. end |
#save!(perms = nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 64 def save! perms = nil (perms) if perms File.open(file_path, 'w') do |f| f.write to_yaml end end |
#save_permissions(perms) ⇒ Object
72 73 74 |
# File 'lib/cantango/permission_engine/yaml_store.rb', line 72 def perms load_from_hash perms end |