Class: TeamApi::JoinerImpl

Inherits:
Object
  • Object
show all
Defined in:
lib/team_api/joiner.rb

Overview

Implements Joiner operations.

Constant Summary collapse

SNIPPET_JOIN_FIELDS =
%w(name full_name first_name last_name self)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ JoinerImpl

site

Jekyll site data object



105
106
107
108
109
# File 'lib/team_api/joiner.rb', line 105

def initialize(site)
  @site = site
  @data = site.data
  @public_mode = site.config['public']
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



102
103
104
# File 'lib/team_api/joiner.rb', line 102

def data
  @data
end

#public_modeObject (readonly)

Returns the value of attribute public_mode.



102
103
104
# File 'lib/team_api/joiner.rb', line 102

def public_mode
  @public_mode
end

#siteObject (readonly)

Returns the value of attribute site.



102
103
104
# File 'lib/team_api/joiner.rb', line 102

def site
  @site
end

#team_indexerObject (readonly)

Returns the value of attribute team_indexer.



102
103
104
# File 'lib/team_api/joiner.rb', line 102

def team_indexer
  @team_indexer
end

Instance Method Details

#get_canonical_reference(reference, errors) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/team_api/joiner.rb', line 155

def get_canonical_reference(reference, errors)
  member = team_indexer.team_member_from_reference reference

  if member.nil?
    errors << 'Unknown Team Member: ' +
      team_indexer.team_member_key(reference)
    nil
  elsif should_exclude_member(reference)
    nil
  else
    member['name'].downcase
  end
end

#init_team_data(data) ⇒ Object



122
123
124
125
# File 'lib/team_api/joiner.rb', line 122

def init_team_data(data)
  @team_indexer = TeamIndexer.new data
  team_indexer.create_indexes
end

#join_project_dataObject



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/team_api/joiner.rb', line 132

def join_project_data
  # A little bit of project data munging. Can go away after the .about.yml
  # convention takes hold, hopefully.
  projects = (data['projects'] ||= {})
  projects.delete_if { |_, p| p['status'] == 'Hold' } if @public_mode
  projects.values.each do |p|
    errors = p['errors'] || []
    join_team_list p['team'], errors
    store_project_errors p, errors unless errors.empty?
  end
end

#join_snippet(snippet) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/team_api/joiner.rb', line 197

def join_snippet(snippet)
  username = snippet['username']
  member = team_indexer.team_member_from_reference username

  if member.nil?
    fail UnknownSnippetUsernameError, username unless public_mode
  else
    member = member.select { |k, _| SNIPPET_JOIN_FIELDS.include? k }
    snippet.merge member
  end
end

#join_snippet_dataObject

Joins snippet data into site.data[‘snippets’] and filters out snippets from team members not appearing in site.data[‘team’] or team_by_email.



187
188
189
190
191
192
193
194
195
# File 'lib/team_api/joiner.rb', line 187

def join_snippet_data
  raw_snippets = data['snippets']
  return if raw_snippets.nil?
  data['snippets'] = raw_snippets.map do |timestamp, snippets|
    joined = snippets.map { |snippet| join_snippet snippet }
      .compact.each { |i| i.delete 'username' }
    [timestamp, joined] unless joined.empty?
  end.compact.to_h
end

#join_team_list(team_list, errors) ⇒ Object

Replaces each member of team_list with a key into the team hash. Values can be:

  • Strings that are already team hash keys

  • Strings that are email addresses

  • Strings that are GitHub usernames

  • Hashes that contain an ‘email’ property

  • Hashes that contain a ‘github’ property



176
177
178
179
180
# File 'lib/team_api/joiner.rb', line 176

def join_team_list(team_list, errors)
  (team_list || []).map! do |reference|
    get_canonical_reference reference, errors
  end.compact! || []
end

#promote_or_remove_dataObject



127
128
129
130
# File 'lib/team_api/joiner.rb', line 127

def promote_or_remove_data
  private_data_method = public_mode ? :remove_data : :promote_data
  HashJoiner.send private_data_method, data, 'private'
end

#restructure_team_data!Object

Jekyll seems to be removing non-alpha characters from the team member names, causing the TeamIndexer to not be able to find any team member matches. This changes all of the team member keys back to what we expect.



114
115
116
117
118
119
120
# File 'lib/team_api/joiner.rb', line 114

def restructure_team_data!
  if !site.data['team'].nil? && site.data['team'].respond_to?(:keys)
    site.data['team'].keys.each do |key|
      site.data['team'][site.data['team'][key]['name']] = site.data['team'].delete(key)
    end
  end
end

#should_exclude_member(reference) ⇒ Object



151
152
153
# File 'lib/team_api/joiner.rb', line 151

def should_exclude_member(reference)
  @public_mode && team_indexer.team_member_is_private(reference)
end

#store_project_errors(project, errors) ⇒ Object



144
145
146
147
148
149
# File 'lib/team_api/joiner.rb', line 144

def store_project_errors(project, errors)
  project['errors'] = errors
  name = project['github'][0] if project['github']
  name ||= project['name']
  data['errors'][name] = errors
end