Module: SimpleRoles::One::RolesMethods::DynamicMethods

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



32
33
34
# File 'lib/simple_roles/one/roles_methods.rb', line 32

def extended base
  base.register_dynamic_methods
end

Instance Method Details

#register_dynamic_methodsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/simple_roles/one/roles_methods.rb', line 37

def register_dynamic_methods
  SimpleRoles.config.valid_roles.each do |r|
    self.class_eval %{
      def self.#{r}s
        where(:role => :#{r})
      end
    }

    define_method :"#{r}?" do
      role == r
    end

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