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



98
99
100
101
102
103
104
105
106
107
# File 'app/models/hubstats/user.rb', line 98

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/models/hubstats/user.rb', line 117

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

.with_pulls_or_comments(start_date, end_date, repo_id = nil) ⇒ Object



109
110
111
112
113
114
115
# File 'app/models/hubstats/user.rb', line 109

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

Instance Method Details

#to_paramObject



139
140
141
# File 'app/models/hubstats/user.rb', line 139

def to_param
  self.
end