Class: Moku::FilePermissionsRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/moku/file_permissions_repo.rb

Overview

Loads and saves role information used by the auth service.

Instance Method Summary collapse

Constructor Details

#initialize(instances_root) ⇒ FilePermissionsRepo

Returns a new instance of FilePermissionsRepo.


12
13
14
# File 'lib/moku/file_permissions_repo.rb', line 12

def initialize(instances_root)
  @instances_root = Pathname.new(instances_root)
end

Instance Method Details

#findObject


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/moku/file_permissions_repo.rb', line 16

def find
  all = load_file(top_path)
  instances = Dir[instances_root/"*"/"permissions.yml"]
    .map {|path| Pathname.new(path) }
    .map {|path| [path.dirname.basename.to_s, load_file(path)] }
    .to_h
  {
    all:       all,
    instances: instances
  }
end

#save(data) ⇒ Object


28
29
30
31
32
33
34
35
36
# File 'lib/moku/file_permissions_repo.rb', line 28

def save(data)
  FileUtils.mkdir_p instances_root
  File.write(instances_root/"permissions.yml", YAML.dump(data.fetch(:all, {})))

  data.fetch(:instances, {}).each_pair do |name, role_users|
    FileUtils.mkdir_p instance_path(name).dirname
    File.write(instance_path(name), YAML.dump(role_users))
  end
end