mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-26 12:30:48 +00:00
Fix more scopes for rails 4 + add rubocop
This commit is contained in:
parent
aa207ac578
commit
143e364812
4 changed files with 32 additions and 34 deletions
1
Gemfile
1
Gemfile
|
@ -79,6 +79,7 @@ group :development do
|
|||
gem 'quiet_assets'
|
||||
gem 'spring', '2.0.2'
|
||||
gem 'web-console'
|
||||
gem 'rubocop'
|
||||
end
|
||||
|
||||
group :test do
|
||||
|
|
|
@ -30,7 +30,7 @@ class Gatherer < ActiveRecord::Base
|
|||
lambda { |team| {:conditions => {:team => team}} }
|
||||
scope :of_user,
|
||||
lambda { |user| {:conditions => {:user_id => user.id}} }
|
||||
scope :lobby, :conditions => "team IS NULL"
|
||||
scope :lobby, -> { where(team: nil) }
|
||||
scope :best,
|
||||
lambda { |gather| {
|
||||
:select => "u.id, u.username, (COUNT(*) / (SELECT COUNT(*) FROM gatherers g3 WHERE g3.user_id = u.id)) AS skill, g4.id",
|
||||
|
@ -42,25 +42,23 @@ class Gatherer < ActiveRecord::Base
|
|||
:having => "g4.id IS NOT NULL",
|
||||
:order => "skill DESC",
|
||||
:limit => 15 } }
|
||||
scope :with_kpd,
|
||||
:select => "gatherers.*, SUM(kills)/SUM(deaths) as kpd, COUNT(rounders.id) as rounds",
|
||||
:joins => "LEFT JOIN rounders ON rounders.user_id = gatherers.user_id",
|
||||
:group => "rounders.user_id",
|
||||
:order => "kpd DESC"
|
||||
scope :lobby_team,
|
||||
lambda { |team| {
|
||||
:conditions => ["gatherers.team IS NULL OR gatherers.team = ?", team],
|
||||
:order => "gatherers.team"} }
|
||||
scope :most_voted, :order => "votes DESC, created_at DESC"
|
||||
scope :with_kpd, -> {
|
||||
select("gatherers.*, SUM(kills)/SUM(deaths) as kpd, COUNT(rounders.id) as rounds").
|
||||
joins("LEFT JOIN rounders ON rounders.user_id = gatherers.user_id").
|
||||
group("rounders.user_id").
|
||||
order("kpd DESC") }
|
||||
scope :lobby_team, -> (team) { conditions("gatherers.team IS NULL OR gatherers.team = ?", team).
|
||||
order("gatherers.team") }
|
||||
scope :most_voted, -> { order("votes DESC, created_at DESC") }
|
||||
scope :not_user,
|
||||
lambda { |user| {:conditions => ["user_id != ?", user.id]} }
|
||||
scope :eject_order, :order => "votes ASC"
|
||||
scope :ordered,
|
||||
:joins => "LEFT JOIN gathers ON captain1_id = gatherers.id OR captain2_id = gatherers.id",
|
||||
:order => "captain1_id, captain2_id, gatherers.id"
|
||||
scope :idle,
|
||||
:joins => "LEFT JOIN users ON users.id = gatherers.user_id",
|
||||
:conditions => ["lastvisit < ?", 30.minutes.ago.utc]
|
||||
scope :eject_order, -> { order("votes ASC") }
|
||||
scope :ordered, -> {
|
||||
joins("LEFT JOIN gathers ON captain1_id = gatherers.id OR captain2_id = gatherers.id").
|
||||
order("captain1_id, captain2_id, gatherers.id") }
|
||||
scope :idle, -> {
|
||||
joins("LEFT JOIN users ON users.id = gatherers.user_id").
|
||||
where("lastvisit < ?", 30.minutes.ago.utc) }
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :gather
|
||||
|
|
|
@ -50,21 +50,20 @@ class Server < ActiveRecord::Base
|
|||
validates_format_of :reservation, :with => /\A[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,5}\z/, :allow_nil => true
|
||||
validates_format_of :pwd, :with => /\A[A-Za-z0-9_\-]*\z/, :allow_nil => true
|
||||
|
||||
scope :ordered, :order => "name"
|
||||
scope :hlds, :conditions => ["domain = ?", DOMAIN_HLDS]
|
||||
scope :ns2, :conditions => ["domain = ?", DOMAIN_NS2]
|
||||
scope :hltvs, :conditions => ["domain = ?", DOMAIN_HLTV]
|
||||
scope :active, :conditions => "active = 1"
|
||||
scope :with_players, :conditions => "players > 0"
|
||||
scope :reserved, :conditions => "reservation IS NOT NULL"
|
||||
scope :unreserved_now, :conditions => "reservation IS NULL"
|
||||
scope :unreserved_hltv_around,
|
||||
lambda { |time| {
|
||||
:select => "servers.*",
|
||||
:joins => "LEFT JOIN matches ON servers.id = matches.hltv_id
|
||||
AND match_time > '#{(time.ago(Match::MATCH_LENGTH).utc).strftime("%Y-%m-%d %H:%M:%S")}'
|
||||
AND match_time < '#{(time.ago(-Match::MATCH_LENGTH).utc).strftime("%Y-%m-%d %H:%M:%S")}'",
|
||||
:conditions => "matches.hltv_id IS NULL"} }
|
||||
scope :ordered, -> { order("name") }
|
||||
scope :hlds, -> { where("domain = ?", DOMAIN_HLDS) }
|
||||
scope :ns2, -> { where("domain = ?", DOMAIN_NS2) }
|
||||
scope :hltvs, -> { where("domain = ?", DOMAIN_HLTV) }
|
||||
scope :active, -> { where("active = 1") }
|
||||
scope :with_players, -> { where("players > 0") }
|
||||
scope :reserved, -> { where("reservation IS NOT NULL") }
|
||||
scope :unreserved_now, -> { where("reservation IS NULL") }
|
||||
scope :unreserved_hltv_around, -> (time) {
|
||||
select("servers.*").
|
||||
joins("LEFT JOIN matches ON servers.id = matches.hltv_id
|
||||
AND match_time > '#{(time.ago(Match::MATCH_LENGTH).utc).strftime("%Y-%m-%d %H:%M:%S")}'
|
||||
AND match_time < '#{(time.ago(-Match::MATCH_LENGTH).utc).strftime("%Y-%m-%d %H:%M:%S")}'").
|
||||
where("matches.hltv_id IS NULL") }
|
||||
|
||||
has_many :logs
|
||||
has_many :matches
|
||||
|
|
|
@ -28,7 +28,7 @@ class Shoutmsg < ActiveRecord::Base
|
|||
scope :typebox, -> { where(shoutable_type: nil, shoutable_id: nil) }
|
||||
scope :last500, -> { includes(:user).order("id DESC").limit(500) }
|
||||
scope :of_object, -> (object, id) { where(shoutable_type: object, shoutable_id: id) }
|
||||
scope :ordered, order("id")
|
||||
scope :ordered, -> { order("id") }
|
||||
|
||||
def domain
|
||||
self[:shoutable_type] ? "shout_#{shoutable_type}_#{shoutable_id}" : "shoutbox"
|
||||
|
|
Loading…
Reference in a new issue