From 700d5a18337f6d4906988cabef4f7c4b20fe1f7a Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 12 Sep 2019 04:02:10 +0500 Subject: [PATCH] Improve code --- app/policies/application_policy.rb | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index ae8931c..7f7c50b 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -3,6 +3,8 @@ class ApplicationPolicy attr_reader :context, :record + delegate :account, :params, to: :context, allow_nil: true + def initialize(context, record) @context = context @record = record @@ -46,14 +48,6 @@ class ApplicationPolicy private - def account - context&.account - end - - def params - context&.params - end - def restricted? Rails.application.restricted? end @@ -61,6 +55,8 @@ private class Scope attr_reader :context, :scope + delegate :account, :params, to: :context, allow_nil: true + def initialize(context, scope) @context = context @scope = scope @@ -76,14 +72,6 @@ private private - def account - context&.account - end - - def params - context&.params - end - def restricted? Rails.application.restricted? end