class Role attr_accessor :name def initialize options = {} name = options[:name].to_sym raise ArgumentError, "Not a valid role label, was: #{name}" if !name.kind_of_label? @name = name role = self if !Role.exists?(@name) Role.roles << role if role end class << self def all roles end def create options = {} self.new options end def roles= new_roles @roles = new_roles end def roles @roles ||= Set.new end def exists? name !where(:name => name.to_sym).empty? end def where options = {} names = [options[:name]].flatten Role.roles.select {|r| names.include?(r.name.to_sym) } end end end