Class: Interferon::GroupSources::Filesystem
- Inherits:
-
Object
- Object
- Interferon::GroupSources::Filesystem
- Defined in:
- lib/interferon/group_sources/filesystem.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Filesystem
constructor
A new instance of Filesystem.
- #list_groups ⇒ Object
Constructor Details
#initialize(options) ⇒ Filesystem
Returns a new instance of Filesystem.
5 6 7 8 9 10 |
# File 'lib/interferon/group_sources/filesystem.rb', line 5 def initialize() raise ArgumentError, 'missing paths for loading groups from filesystem' \ unless ['paths'] @paths = ['paths'] end |
Instance Method Details
#list_groups ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/interferon/group_sources/filesystem.rb', line 12 def list_groups groups = {} aliases = {} @paths.each do |path| path = File.(path) unless Dir.exist?(path) log.warn("no such directory #{path} for reading group files") next end Dir.glob(File.join(path, '*.{json,yml,yaml}')).each do |group_file| begin group = YAML.parse(File.read(group_file)) rescue YAML::SyntaxError => e log.error("syntax error in group file #{group_file}: #{e}") rescue StandardError => e log.warn("error reading group file #{group_file}: #{e}") else group = group.to_ruby if group['people'] groups[group['name']] = group['people'] || [] elsif group['alias_for'] aliases[group['name']] = { group: group['alias_for'], group_file: group_file } end end end end aliases.each do |aliased_group, group_info| group = group_info[:group] group_file = group_info[:group_file] if groups.include?(group) groups[aliased_group] = groups[group] else log.warn("Alias not found for #{group} but used by #{aliased_group} in #{group_file}") end end groups end |