Sha256: 84dc3d7b1a616d09e7bf42d1eedfbddf9f827511ee2eb009d45540c97e9897e4

Contents?: true

Size: 1.6 KB

Versions: 31

Compression:

Stored size: 1.6 KB

Contents

module Hubstats
  class Label < ActiveRecord::Base

    def self.record_timestamps; false; end

    # Various checks that can be used to filter and find info about labels.
    scope :with_ids, lambda {|pull_ids| (where("hubstats_labels_pull_requests.pull_request_id" => pull_ids))}
    scope :with_state, lambda {|state| (where(state: state) unless state == 'all') if state}

    # Public - Counts all of the labels that are assigned to one of the PRs that is passed in. This is then 
    # merged with the list of PRs. It also shows a count of the number of PRs with each specific label.
    #
    # pull_requests - the PRs that are shown on the given index page
    #
    # Returns - the labels data
    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

    has_and_belongs_to_many :pull_requests, :join_table => 'hubstats_labels_pull_requests'

    # Public - Checks if the label is currently existing, and if it isn't, then makes a new label with 
    # the specifications that are passed in.
    #
    # label - the info that's passed in about the new label
    #
    # Returns - the label 
    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

  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
hubstats-1.2.1 app/models/hubstats/label.rb
hubstats-1.2.0 app/models/hubstats/label.rb
hubstats-1.1.0 app/models/hubstats/label.rb
hubstats-1.0.0 app/models/hubstats/label.rb
hubstats-1.0.0.beta3 app/models/hubstats/label.rb
hubstats-1.0.0.beta2 app/models/hubstats/label.rb
hubstats-1.0.0.beta1 app/models/hubstats/label.rb
hubstats-1.0.0.beta app/models/hubstats/label.rb
hubstats-0.12.2 app/models/hubstats/label.rb
hubstats-0.12.1 app/models/hubstats/label.rb
hubstats-0.12.0 app/models/hubstats/label.rb
hubstats-0.11.5 app/models/hubstats/label.rb
hubstats-0.11.4 app/models/hubstats/label.rb
hubstats-0.11.1 app/models/hubstats/label.rb
hubstats-0.11.0 app/models/hubstats/label.rb
hubstats-0.10.0 app/models/hubstats/label.rb
hubstats-0.9.5 app/models/hubstats/label.rb
hubstats-0.9.4 app/models/hubstats/label.rb
hubstats-0.9.3 app/models/hubstats/label.rb
hubstats-0.9.2 app/models/hubstats/label.rb