diff options
author | jomo <github@jomo.tv> | 2013-10-07 04:59:21 +0200 |
---|---|---|
committer | jomo <github@jomo.tv> | 2013-10-07 04:59:21 +0200 |
commit | 5fac505a31e6fdaf108ac29cf927ec097c925632 (patch) | |
tree | cc6b2c838e85dc4b3b34a1c5504b89a20f1027d7 /app/models/role.rb | |
parent | 27613877038bb37488e1f71902071b82c655b304 (diff) |
another big commit :D
Diffstat (limited to 'app/models/role.rb')
-rw-r--r-- | app/models/role.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/models/role.rb b/app/models/role.rb new file mode 100644 index 0000000..a01f301 --- /dev/null +++ b/app/models/role.rb @@ -0,0 +1,38 @@ +class Role < ActiveRecord::Base + include Comparable + has_many :users + attr_accessible :name, :value + + def to_s + self.name + end + + def to_i + self.value + end + + def is? (name) + !!(Role.find_by_name(name) == self) + end + + def self.get (name) + Role.find_by_name(name) + end + + def <=> (role) + if role.is_a?(Role) + self.value - role.value + elsif role.is_a?(Symbol) + self <=> Role.find_by_name(role) + else + raise "Cannot compare Role with #{role.class}" + end + end + + def self.all_until (role) + Role.all.select do |r| + r <= role + end + end + +end
\ No newline at end of file |