Class: Hubstats::User

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_or_update(github_user) ⇒ Object



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

def self.create_or_update(github_user)
  github_user[:role] = github_user.delete :type  ##changing :type in to :role
  github_user = github_user.to_h.with_indifferent_access unless github_user.is_a? Hash

  user_data = github_user.slice(*Hubstats::User.column_names.map(&:to_sym))
  
  user = Hubstats::User.where(:id => user_data[:id]).first_or_create(user_data)
  return user if user.update_attributes(user_data)
  Rails.logger.warn user.errors.inspect
end

.custom_order(order_params) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/hubstats/user.rb', line 101

def self.custom_order(order_params)
  if order_params
    order = order_params.include?('asc') ? "ASC" : "DESC"
    case order_params.split('-').first
    when 'pulls'
      order("pull_request_count #{order}")
    when 'comments'
      order("comment_count #{order}")
    when 'additions'
      order("average_additions #{order}")
    when 'deletions'
      order("average_deletions #{order}")
    else
      order("pull_request_count #{order}")
    end
  else 
    order("pull_request_count DESC")
  end
end

.with_pulls_or_comments(time, repo_id = nil) ⇒ Object



93
94
95
96
97
98
99
# File 'app/models/hubstats/user.rb', line 93

def self.with_pulls_or_comments(time, repo_id = nil)
  if repo_id
    pull_and_comment_count_by_repo(time,repo_id).weighted_sort
  else
    pull_and_comment_count(time).weighted_sort
  end
end

Instance Method Details

#to_paramObject



121
122
123
# File 'app/models/hubstats/user.rb', line 121

def to_param
  self.
end