metamaps--metamaps/app/services/perm.rb

37 lines
594 B
Ruby
Raw Normal View History

class Perm
# e.g. Perm::ISSIONS
2016-06-30 11:42:46 +08:00
ISSIONS = [:commons, :public, :private].freeze
class << self
def short(permission)
case permission
when :commons
2016-06-30 11:42:46 +08:00
'co'
when :public
2016-06-30 11:42:46 +08:00
'pu'
when :private
2016-06-30 11:42:46 +08:00
'pr'
else
2016-06-30 11:42:46 +08:00
raise 'Invalid permission'
end
end
def long(perm)
case perm
2016-06-30 11:42:46 +08:00
when 'co'
:commons
2016-06-30 11:42:46 +08:00
when 'pu'
:public
2016-06-30 11:42:46 +08:00
when 'pr'
:private
else
2016-06-30 11:42:46 +08:00
raise 'Invalid short permission'
end
end
2016-06-30 11:42:46 +08:00
def valid?(permission)
ISSIONS.include? permission
end
end
end