【发布时间】:2016-12-21 17:41:52
【问题描述】:
在使用 Ruby gem Pundit 时,我意识到我不确定 Ruby 中某些命名空间的工作方式,并且我不喜欢我心中的奥秘/不确定性。
Pundit 建议您像这样设置application_policy.rb:
class ApplicationPolicy
class Scope
.
.
.
end
end
类内部实际发生的事情并不重要,重要的是类的结构。
然后,您为从 ApplicationPolicy 继承的特定资源指定策略,例如 post_policy.rb:
class PostPolicy < ApplicationPolicy
class Scope < Scope
end
end
我的一般问题是,在我的 PostPolicy 中,当我声明 Scope < Scope 时,父 Scope 指的是什么?它会自动在外部类的父类中获得命名空间吗?那么它与从ApplicationPolicy::Scope 继承本质上是一样的吗?我很难找到自己回答这个问题的方法,谢谢!
【问题讨论】:
标签: ruby namespaces ruby-2.0 pundit