Class: Hubstats::Team

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

Class Method Summary collapse

Instance 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



65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/hubstats/team.rb', line 65

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

.designed_for_hubstats?(description) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
# File 'app/models/hubstats/team.rb', line 100

def self.designed_for_hubstats?(description)
  description.include?("hubstats") ||
  description.include?("Hubstats") ||
  description.include?("hub") ||
  description.include?("Hub")
end

.order_by_nameObject

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

Returns - the data ordered alphabetically by name



96
97
98
# File 'app/models/hubstats/team.rb', line 96

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



84
85
86
87
88
89
90
91
# File 'app/models/hubstats/team.rb', line 84

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

Instance Method Details

#deprecate_teamObject

Public - Will change the team’s hubstats column to false

Returns - the team



53
54
55
56
# File 'app/models/hubstats/team.rb', line 53

def deprecate_team
  self.update_column(:hubstats, false)
  self.save!
end