Sha256: d00e21be87fe594d141d88700434070e4cdc3ae0fd499b3758b6a068e0ac7520

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

module Hubstats
  class Label < ActiveRecord::Base
    scope :with_a_pull_request, lambda { |pull_ids|
      select("hubstats_labels.*")
      .select("COUNT(hubstats_labels_pull_requests.pull_request_id) AS pull_request_count")
      .joins("LEFT JOIN hubstats_labels_pull_requests ON hubstats_labels_pull_requests.label_id = hubstats_labels.id")
      .with_ids(pull_ids)
      .having("pull_request_count > 0")
      .group("hubstats_labels.id")
    }

    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}

    attr_accessible :url, :name, :color

    has_and_belongs_to_many :pull_requests, :join_table => 'hubstats_labels_pull_requests'

    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

11 entries across 11 versions & 1 rubygems

Version Path
hubstats-0.3.11 app/models/hubstats/label.rb
hubstats-0.3.10 app/models/hubstats/label.rb
hubstats-0.3.9 app/models/hubstats/label.rb
hubstats-0.3.8 app/models/hubstats/label.rb
hubstats-0.3.7 app/models/hubstats/label.rb
hubstats-0.3.6 app/models/hubstats/label.rb
hubstats-0.3.5 app/models/hubstats/label.rb
hubstats-0.3.4 app/models/hubstats/label.rb
hubstats-0.3.3 app/models/hubstats/label.rb
hubstats-0.3.2 app/models/hubstats/label.rb
hubstats-0.3.1 app/models/hubstats/label.rb