Sha256: ffa37d768f28e8244bf65684294a42fa2aa0f6cae8e7eefe794c81f4d93d5249

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

module Roles::Base
  def valid_roles_are(*role_list)
    strategy_class.valid_roles = role_list.to_symbols
    if role_class_name
      role_list.each do |name| 
        role_class_name.new(name)
      end
    end
  end
end

class Role
  attr_accessor :name
  
  def self.find_role role_name    
    roles.to_a.select do |r| 
      r.name.to_sym == role_name.to_sym
    end.first
  end  

  def self.find_roles *role_names
    result = Set.new
    role_names.to_symbols.each do |role_name| 
      found_role = find_role(role_name)
      result << found_role if found_role
    end
    result
  end

  class << self
    attr_accessor :roles
    
    def all
      roles.to_a
    end
    
    def names
      roles.map(&:name)
    end
  end    
  
  def initialize name
    @name = name
    self.class.roles ||= Set.new
    self.class.roles << self
  end  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roles_generic-0.2.7 lib/roles_generic/role.rb