Class: Policy

Inherits:
Object
  • Object
show all
Includes:
DefaultPolicy
Defined in:
app/policies/policy.rb

Defined Under Namespace

Modules: DefaultPolicy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DefaultPolicy

#create?, #destroy?, #edit?, #index, #new?, #show?, #update?

Constructor Details

#initialize(user, record = nil) ⇒ Policy

Returns a new instance of Policy.



38
39
40
41
# File 'app/policies/policy.rb', line 38

def initialize(user, record = nil)
  @user = user
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



36
37
38
# File 'app/policies/policy.rb', line 36

def record
  @record
end

#userObject (readonly)

Returns the value of attribute user.



36
37
38
# File 'app/policies/policy.rb', line 36

def user
  @user
end

Class Method Details

.collection(user) ⇒ Object



52
53
54
# File 'app/policies/policy.rb', line 52

def collection(user)
  new(user)
end

.for(user, object) ⇒ Object



44
45
46
47
48
49
50
# File 'app/policies/policy.rb', line 44

def for(user, object)
  if object.is_a?(Class)
    "#{object}Policy".constantize.collection(user)
  else
    "#{object.class}Policy".constantize.member(user, object)
  end
end

.member(user, record) ⇒ Object



56
57
58
# File 'app/policies/policy.rb', line 56

def member(user, record)
  new(user, record)
end