Module: Sequel::Privacy::PolicyDSL

Extended by:
T::Helpers, T::Sig
Defined in:
lib/sequel/privacy/policy_dsl.rb

Overview

DSL for defining custom policies. Extend your policy module with this to get the ‘policy` method.

Example:

module P
  extend Sequel::Privacy::PolicyDSL

  AlwaysDeny = Sequel::Privacy::BuiltInPolicies::AlwaysDeny

  policy :AllowAdmins, ->(actor) {
    allow if actor.is_role?(:admin)
  }, 'Allow admin users', cacheable: true
end

Instance Method Summary collapse

Instance Method Details

#policy(name, lam, comment = nil, cacheable: true, single_match: false, cache_by: nil, allow_anonymous: false) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sequel/privacy/policy_dsl.rb', line 49

def policy(name, lam, comment = nil, cacheable: true, single_match: false, cache_by: nil,
           allow_anonymous: false)
  p = Policy.new(&lam).setup(
    policy_name: name,
    comment: comment,
    cacheable: cacheable,
    single_match: single_match,
    cache_by: cache_by,
    allow_anonymous: allow_anonymous
  )
  const_set(name, p)
end