Class: Rolify::Adapter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rolify/adapters/base.rb

Direct Known Subclasses

ResourceAdapterBase, RoleAdapterBase

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role_cname, user_cname) ⇒ Base

Returns a new instance of Base.



4
5
6
7
# File 'lib/rolify/adapters/base.rb', line 4

def initialize(role_cname, user_cname)
  @role_cname = role_cname
  @user_cname = user_cname
end

Class Method Details

.create(adapter, role_cname, user_cname) ⇒ Object



21
22
23
24
25
# File 'lib/rolify/adapters/base.rb', line 21

def self.create(adapter, role_cname, user_cname)
  load "rolify/adapters/#{Rolify.orm}/#{adapter}.rb"
  load "rolify/adapters/#{Rolify.orm}/scopes.rb"
  Rolify::Adapter.const_get(adapter.camelize.to_sym).new(role_cname, user_cname)
end

Instance Method Details

#relation_types_for(relation) ⇒ Object



27
28
29
# File 'lib/rolify/adapters/base.rb', line 27

def relation_types_for(relation)
  relation.descendants.map(&:to_s).push(relation.to_s)
end

#role_classObject



9
10
11
# File 'lib/rolify/adapters/base.rb', line 9

def role_class
  @role_cname.constantize
end

#role_tableObject



17
18
19
# File 'lib/rolify/adapters/base.rb', line 17

def role_table
  role_class.table_name
end

#user_classObject



13
14
15
# File 'lib/rolify/adapters/base.rb', line 13

def user_class
  @user_cname.constantize
end