discourse/lib/trust_level.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
584 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-09-04 18:42:18 -04:00
class InvalidTrustLevel < StandardError; end
2013-03-01 07:07:44 -05:00
class TrustLevel
class << self
2014-09-04 18:42:18 -04:00
def [](level)
raise InvalidTrustLevel if !valid?(level)
level
2014-09-04 18:42:18 -04:00
end
def levels
@levels ||= Enum.new(:newuser, :basic, :member, :regular, :leader, start: 0)
end
def valid?(level)
valid_range === level
end
def valid_range
(0..4)
end
def compare(current_level, level)
(current_level || 0) >= level
2013-02-05 14:16:51 -05:00
end
def name(level)
I18n.t("js.trust_levels.names.#{levels[level]}")
end
2013-02-05 14:16:51 -05:00
end
2013-02-05 14:16:51 -05:00
end