Class: Hubstats::Team

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/hubstats/team.rb

Class Method Summary collapse

Class Method Details

.create_or_update(github_team) ⇒ Object

Public - Checks if the team is currently existing, and if it isn’t, then makes a new team with the specifications that are passed in. We are assuming that if it is not already existent, then we probably don’t really care about the team, so our hubstats boolean will be set to false.

github_team - the info that’s passed in about the new or updated team

Returns - the team



58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/hubstats/team.rb', line 58

def self.create_or_update(github_team)
  github_team = github_team.to_h.with_indifferent_access if github_team.respond_to? :to_h

  team_data = github_team.slice(*Hubstats::Team.column_names.map(&:to_sym))
  team = where(:id => team_data[:id]).first_or_create(team_data)

  team_data[:hubstats] = true

  return team if team.update_attributes(team_data)
  Rails.logger.warn team.errors.inspect
end

.order_by_nameObject

Public - Orders the list of data by name (alphabetical)

Returns - the data ordered alphabetically by name



89
90
91
# File 'app/models/hubstats/team.rb', line 89

def self.order_by_name
  order("name ASC")
end

.record_timestampsObject



4
# File 'app/models/hubstats/team.rb', line 4

def self.record_timestamps; false; end

.update_users_in_team(team, user, action) ⇒ Object

Public - Adds or removes a user from a team

team - a hubstats team that we wish to edit the users of user - a hubstats user that we wish to remove or add to the team action - whether the user is to be removed or added (string)

Returns - nothing



77
78
79
80
81
82
83
84
# File 'app/models/hubstats/team.rb', line 77

def self.update_users_in_team(team, user, action)
  if action == "added"
    team.users << user
  elsif action == "removed"
    team.users.delete(user)
  end
  team.save!
end