Class: CanTango::PermissionEngine::YamlStore

Inherits:
Store
  • Object
show all
Defined in:
lib/cantango/permission_engine/yaml_store.rb

Instance Attribute Summary collapse

Attributes inherited from Store

#name, #options

Class Method Summary collapse

Instance Method Summary collapse

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, options = {}
  super
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/cantango/permission_engine/yaml_store.rb', line 6

def path
  @path
end

Class Method Details

.create(name, options = {}) ⇒ Object



15
16
17
# File 'lib/cantango/permission_engine/yaml_store.rb', line 15

def self.create name, options = {}
  super
end

Instance Method Details

#load!Object



19
20
21
# File 'lib/cantango/permission_engine/yaml_store.rb', line 19

def load!
  loader.load!
end

#load_from_hash(hash) ⇒ Object



23
24
25
# File 'lib/cantango/permission_engine/yaml_store.rb', line 23

def load_from_hash hash
  loader.load_from_hash hash
end

#permissionsObject

@stanislaw: don’t like this, because what if loader#load! will be called twice during object’s (YamlStore.new) life time!



29
30
31
# File 'lib/cantango/permission_engine/yaml_store.rb', line 29

def permissions
  @permissions ||= loader.permissions
end

#save!(perms = nil) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/cantango/permission_engine/yaml_store.rb', line 60

def save! perms = nil
  save_permissions(perms) if perms

  File.open(file_path, 'w') do |f|
    f.write to_yaml
  end
end

#save_permissions(perms) ⇒ Object



68
69
70
# File 'lib/cantango/permission_engine/yaml_store.rb', line 68

def save_permissions(perms)
  load_from_hash perms
end