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.


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

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

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record


34
35
36
# File 'app/policies/policy.rb', line 34

def record
  @record
end

#userObject (readonly)

Returns the value of attribute user


34
35
36
# File 'app/policies/policy.rb', line 34

def user
  @user
end

Class Method Details

.collection(user) ⇒ Object


50
51
52
# File 'app/policies/policy.rb', line 50

def collection(user)
  new(user)
end

.for(user, object) ⇒ Object


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

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


54
55
56
# File 'app/policies/policy.rb', line 54

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