Class: Squad
- Inherits:
-
Object
- Object
- Squad
- Defined in:
- lib/terraorg/model/squad.rb
Defined Under Namespace
Classes: Team
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#teams ⇒ Object
Returns the value of attribute teams.
Instance Method Summary collapse
-
#everyone(location: nil) ⇒ Object
Everyone including associates on all subteams in the squad.
- #generate_tf(org_id) ⇒ Object
- #get_acl_groups(org_id) ⇒ Object
-
#initialize(id, parsed_data, people, gsuite_domain, slack_domain) ⇒ Squad
constructor
A new instance of Squad.
- #manager ⇒ Object
-
#members ⇒ Object
Full-time members of all subteams in this squad.
- #to_h ⇒ Object
- #to_md(platoon_name, org_id) ⇒ Object
- #unique_name(org_id, location) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(id, parsed_data, people, gsuite_domain, slack_domain) ⇒ Squad
Returns a new instance of Squad.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/terraorg/model/squad.rb', line 70 def initialize(id, parsed_data, people, gsuite_domain, slack_domain) @gsuite_domain = gsuite_domain @slack_domain = slack_domain @id = id @metadata = parsed_data.fetch('metadata', {}) @name = parsed_data.fetch('name') @people = people teams_arr = parsed_data.fetch('team', []).map do |t| Team.new(t, people) end @teams = Hash[teams_arr.map { |t| [t.location, t] }] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
21 22 23 |
# File 'lib/terraorg/model/squad.rb', line 21 def id @id end |
#metadata ⇒ Object
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/terraorg/model/squad.rb', line 21 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/terraorg/model/squad.rb', line 21 def name @name end |
#teams ⇒ Object
Returns the value of attribute teams.
21 22 23 |
# File 'lib/terraorg/model/squad.rb', line 21 def teams @teams end |
Instance Method Details
#everyone(location: nil) ⇒ Object
Everyone including associates on all subteams in the squad.
85 86 87 88 89 90 91 |
# File 'lib/terraorg/model/squad.rb', line 85 def everyone(location: nil) @teams.select { |l, t| location == nil || l == location }.map { |_, t| t.everyone }.flatten end |
#generate_tf(org_id) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/terraorg/model/squad.rb', line 148 def generate_tf(org_id) groups = get_acl_groups(org_id) groups.map { |id, group| description = "#{group.fetch('name')} (terraorg)" <<-EOF resource "okta_group" "#{id}" { name = "#{id}" description = "#{description}" users = #{Util.persons_tf(group.fetch('members'))} } #{Util.gsuite_group_tf(id, @gsuite_domain, group.fetch('members'), description)} EOF }.join("\n\n") end |
#get_acl_groups(org_id) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/terraorg/model/squad.rb', line 100 def get_acl_groups(org_id) # each geographically located subteam groups = Hash[@teams.map { |location, team| [unique_name(org_id, location), {'name' => "#{@name} squad members based in #{location}", 'members' => team.everyone}] }] # combination of all subteams groups[unique_name(org_id, nil)] = {'name' => "#{@name} squad worldwide members", 'members' => everyone} groups end |
#manager ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/terraorg/model/squad.rb', line 165 def manager m = @metadata['manager'] if m return @people.get_or_create!(m) else return nil end end |
#members ⇒ Object
Full-time members of all subteams in this squad
94 95 96 97 98 |
# File 'lib/terraorg/model/squad.rb', line 94 def members @teams.map { |_, t| t.members }.flatten end |
#to_h ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/terraorg/model/squad.rb', line 174 def to_h # Output a canonical (sorted, formatted) version of this Squad. # - Subteams are sorted by location lexically obj = { 'id' => @id, 'name' => @name } obj['team'] = @teams.values.sort_by { |t| t.location }.map(&:to_h) obj['metadata'] = @metadata if @metadata obj end |
#to_md(platoon_name, org_id) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/terraorg/model/squad.rb', line 124 def to_md(platoon_name, org_id) pm = @metadata.fetch('pm', []) pm = pm.map { |p| @people.get_or_create!(p).name }.join(', ') sme = @metadata.fetch('sme', '') if !sme.empty? sme = @people.get_or_create!(sme).name end manager = @metadata.fetch('manager', '') if !manager.empty? manager = @people.get_or_create!(manager).name end subteam_members = @teams.values.map(&:to_md).join(' / ') email = "#{unique_name(org_id, nil)}@#{@gsuite_domain}" slack = @metadata.fetch('slack', '') if slack slack = "[#{slack}](https://#{@slack_domain}/app_redirect?channel=#{slack.gsub(/^#/, '')})" end # platoon name, squad name, PM, email list, SME, slack, # full time members, squad manager, members "|#{platoon_name}|#{@name}|#{pm}|[#{email}](#{email})|#{sme}|#{slack}|#{members.size}|#{manager}|#{subteam_members}|" end |
#unique_name(org_id, location) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/terraorg/model/squad.rb', line 112 def unique_name(org_id, location) if location "#{org_id}-squad-#{@id}-#{location.downcase}" else "#{org_id}-squad-#{@id}" end end |
#validate! ⇒ Object
120 121 122 |
# File 'lib/terraorg/model/squad.rb', line 120 def validate! @teams.each(&:validate!) end |