Module: SimpleRoles::Many::RolesMethods::DynamicMethods

Defined in:
lib/simple_roles/many/roles_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



14
15
16
# File 'lib/simple_roles/many/roles_methods.rb', line 14

def extended base
  base.register_dynamic_methods
end

Instance Method Details

#register_dynamic_methodsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/simple_roles/many/roles_methods.rb', line 19

def register_dynamic_methods
  valid_roles.each do |role|
    class_eval %{
      def self.#{role}s
        Role.find_by_name("#{role}").users
      end

      def self.#{role}s_ids
        Role.find_by_name("#{role}").user_ids
      end
    }

    define_method :"#{role}?" do
      roles.include?(:"#{role}")
    end

    alias_method :"is_#{role}?", :"#{role}?"
  end
end

#valid_rolesObject



39
40
41
# File 'lib/simple_roles/many/roles_methods.rb', line 39

def valid_roles
  SimpleRoles::Configuration.valid_roles
end