Sha256: 98d1fa632c97d66b096df4e89da519ea5a2874da960aff2c1060a669c2cfc482

Contents?: true

Size: 829 Bytes

Versions: 6

Compression:

Stored size: 829 Bytes

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)) unless pull_ids.blank? }

    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'

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hubstats-0.0.19 app/models/hubstats/label.rb
hubstats-0.0.18 app/models/hubstats/label.rb
hubstats-0.0.17 app/models/hubstats/label.rb
hubstats-0.0.16 app/models/hubstats/label.rb
hubstats-0.0.15 app/models/hubstats/label.rb
hubstats-0.0.14 app/models/hubstats/label.rb