You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
class Hack < ApplicationRecord
|
|
|
|
|
# status: 0 未发布; 1已发布
|
|
|
|
|
# diffcult: 难度 1:简单;2:中等; 3:困难
|
|
|
|
|
# 编程题
|
|
|
|
|
validates_length_of :name, maximum: 60
|
|
|
|
|
# 测试集
|
|
|
|
|
has_many :hack_sets, ->{order("position asc")}, :dependent => :destroy
|
|
|
|
|
# 代码
|
|
|
|
|
has_many :hack_codes, :dependent => :destroy
|
|
|
|
|
has_many :hack_user_lastest_codes, :dependent => :destroy
|
|
|
|
|
has_many :discusses, as: :dis, dependent: :destroy
|
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
|
|
scope :published, -> { where(status: 1) }
|
|
|
|
|
scope :opening, -> {where(open_or_not: 1)}
|
|
|
|
|
scope :mine, -> (author_id){ where(user_id: author_id) }
|
|
|
|
|
|
|
|
|
|
def language
|
|
|
|
|
if hack_codes.count == 1
|
|
|
|
|
hack_codes.first.language
|
|
|
|
|
else
|
|
|
|
|
hack_codes.pluck(:language).first
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def code
|
|
|
|
|
if hack_codes.count == 1
|
|
|
|
|
tran_base64_decode64(hack_codes.first.code)
|
|
|
|
|
else
|
|
|
|
|
tran_base64_decode64(hack_codes.pluck(:code))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 用于用户调试的第一个测试用例
|
|
|
|
|
def input_test_case
|
|
|
|
|
hack_sets.first&.input
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|