Class: Posgra::DSL::Roles
- Inherits:
-
Object
- Object
- Posgra::DSL::Roles
- Includes:
- Logger::Helper, TemplateHelper, Utils::Helper
- Defined in:
- lib/posgra/dsl/roles.rb
Defined Under Namespace
Classes: Group
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, options = {}, &block) ⇒ Roles
constructor
A new instance of Roles.
- #result ⇒ Object
Methods included from Utils::Helper
Methods included from TemplateHelper
Methods included from Logger::Helper
Constructor Details
#initialize(path, options = {}, &block) ⇒ Roles
Returns a new instance of Roles.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/posgra/dsl/roles.rb', line 37 def initialize(path, = {}, &block) @path = path @options = @result = { :users => [], :users_by_group => {}, } @context = Hashie::Mash.new( :path => path, :options => , :templates => {}, ) instance_eval(&block) end |
Class Method Details
.eval(dsl, path, options = {}) ⇒ Object
6 7 8 9 10 |
# File 'lib/posgra/dsl/roles.rb', line 6 def self.eval(dsl, path, = {}) self.new(path, ) do eval(dsl, binding, path) end end |
Instance Method Details
#result ⇒ 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 |
# File 'lib/posgra/dsl/roles.rb', line 12 def result @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 |