lib/posgra/dsl/roles.rb in posgra-0.1.8 vs lib/posgra/dsl/roles.rb in posgra-0.1.9

- old
+ new

@@ -8,11 +8,31 @@ eval(dsl, binding, path) end end def result - @result.fetch(:users).uniq + @result[:users].uniq! + + group_users = @result[:users_by_group].flat_map do |group, users| + if users.empty? + [group, nil] + else + users.map {|u| [group, u] } + end + end + + new_users_by_group = {} + + group_users.each do |group, user| + next unless [group, user].any? {|i| not i.nil? and matched?(i, @options[:include_role], @options[:exclude_role]) } + new_users_by_group[group] ||= [] + new_users_by_group[group] << user if user + end + + new_users_by_group.values.each(&:uniq!) + @result[:users_by_group] = new_users_by_group + @result end def initialize(path, options = {}, &block) @path = path @@ -57,11 +77,8 @@ end end def group(name, &block) name = name.to_s - - if matched?(name, @options[:include_role], @options[:exclude_role]) - @result[:users_by_group][name] = Posgra::DSL::Roles::Group.new(@context, name, @options, &block).result - end + @result[:users_by_group][name] = Posgra::DSL::Roles::Group.new(@context, name, @options, &block).result end end