Class: ActionAuthorization::BasePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/action_authorization/base_policy.rb

Direct Known Subclasses

NullPolicy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, object = nil) ⇒ BasePolicy

Returns a new instance of BasePolicy.



19
20
21
22
# File 'lib/action_authorization/base_policy.rb', line 19

def initialize(user, object = nil)
  self.user = user
  self.object = object
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



5
6
7
# File 'lib/action_authorization/base_policy.rb', line 5

def object
  @object
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/action_authorization/base_policy.rb', line 5

def user
  @user
end

Class Method Details

.inherited(klass) ⇒ Object

create alias to object from subclass name



25
26
27
28
# File 'lib/action_authorization/base_policy.rb', line 25

def self.inherited(klass)
  super
  klass.send(:alias_method, klass.type.underscore, :object)
end

.typeObject



7
8
9
# File 'lib/action_authorization/base_policy.rb', line 7

def self.type
  name.delete_suffix("Policy")
end

.type_classObject



11
12
13
14
15
# File 'lib/action_authorization/base_policy.rb', line 11

def self.type_class
  type.constantize
rescue NameError
  NilClass
end

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/action_authorization/base_policy.rb', line 42

def create?
  authorized?
end

#destroy?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/action_authorization/base_policy.rb', line 54

def destroy?
  create?
end

#edit?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/action_authorization/base_policy.rb', line 46

def edit?
  update?
end

#index?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/action_authorization/base_policy.rb', line 30

def index?
  authorized?
end

#new?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/action_authorization/base_policy.rb', line 38

def new?
  create?
end

#show?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/action_authorization/base_policy.rb', line 34

def show?
  authorized?
end

#update?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/action_authorization/base_policy.rb', line 50

def update?
  authorized?
end