2013-03-01 07:07:44 -05:00
|
|
|
require_dependency 'enum'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-03-01 07:07:44 -05:00
|
|
|
class TrustLevel
|
2013-02-05 14:16:51 -05:00
|
|
|
attr_reader :id, :name
|
|
|
|
|
2013-02-28 08:08:56 -05:00
|
|
|
class << self
|
|
|
|
def levels
|
2013-03-01 07:07:44 -05:00
|
|
|
@levels ||= Enum.new(
|
2013-04-17 19:11:13 -04:00
|
|
|
:newuser, :basic, :regular, :leader, :elder, start: 0
|
2013-03-01 07:07:44 -05:00
|
|
|
)
|
2013-02-28 08:08:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
|
|
|
levels.map do |name_key, id|
|
|
|
|
TrustLevel.new(name_key, id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_level?(level)
|
2013-03-01 07:07:44 -05:00
|
|
|
levels.valid?(level)
|
2013-02-28 08:08:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def compare(current_level, level)
|
2013-04-17 19:11:13 -04:00
|
|
|
(current_level || levels[:newuser]) >= levels[level] rescue binding.pry
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(name_key, id)
|
2013-02-25 11:42:20 -05:00
|
|
|
@name = I18n.t("trust_levels.#{name_key}.title")
|
2013-02-05 14:16:51 -05:00
|
|
|
@id = id
|
|
|
|
end
|
|
|
|
|
|
|
|
def serializable_hash
|
2013-02-28 08:08:56 -05:00
|
|
|
{ id: @id, name: @name }
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|