Class: Hubstats::Label

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

Class Method Summary collapse

Class Method Details

.count_by_pull_requests(pull_requests) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/models/hubstats/label.rb', line 4

def self.count_by_pull_requests(pull_requests)
  select("hubstats_labels.*")
   .select("COUNT(hubstats_labels_pull_requests.pull_request_id) AS pull_request_count")
   .joins(:pull_requests).merge(pull_requests)
   .having("pull_request_count > 0")
   .group("hubstats_labels.id")
   .order("pull_request_count DESC")
end

.first_or_create(label) ⇒ Object



21
22
23
24
25
26
27
# File 'app/models/hubstats/label.rb', line 21

def self.first_or_create(label)
  if exists = Hubstats::Label.where(name: label[:name]).first
    return exists
  else
    Label.new(name: label[:name], url: label[:url], color: label[:color])
  end
end