Class: GridCLI::SubGrids

Inherits:
YMLHash
  • Object
show all
Defined in:
lib/gridcli/subgrids.rb

Instance Method Summary collapse

Methods inherited from YMLHash

#default_config, #save

Constructor Details

#initializeSubGrids

Returns a new instance of SubGrids.



3
4
5
# File 'lib/gridcli/subgrids.rb', line 3

def initialize
  super "subgrids"
end

Instance Method Details

#get_group(group, stack = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gridcli/subgrids.rb', line 7

def get_group(group, stack=nil)
  stack ||= []
  if stack.include? group
    puts "Recursive subgrid definition detected."
    exit 1
  end
  stack << group

  fetch(group, "").split(" ").map { |user|
    user.start_with?('@') ? get_group(user, stack) : user
  }.flatten
end

#groupsObject



20
21
22
# File 'lib/gridcli/subgrids.rb', line 20

def groups
  keys
end

#resolve(userlist) ⇒ Object



29
30
31
32
33
# File 'lib/gridcli/subgrids.rb', line 29

def resolve(userlist)
  userlist.map { |user|
    user.start_with?('@') ? get_group(user) : user
  }
end

#set_group(name, members) ⇒ Object



24
25
26
27
# File 'lib/gridcli/subgrids.rb', line 24

def set_group(name, members)
  self[name] = members.join(" ")
  save
end