Class: Sequel::Privacy::PolicyFactory
- Inherits:
-
Object
- Object
- Sequel::Privacy::PolicyFactory
- Extended by:
- T::Sig
- Defined in:
- lib/sequel/privacy/policy_factory.rb
Overview
A PolicyFactory captures definition-time arguments and returns concrete Policy instances that can be registered in a privacy policy chain.
Instance Attribute Summary collapse
-
#factory_name ⇒ Object
readonly
Returns the value of attribute factory_name.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(factory_name, factory, comment: nil, cacheable: true, single_match: false, cache_by: nil, allow_anonymous: false) ⇒ PolicyFactory
constructor
A new instance of PolicyFactory.
Constructor Details
#initialize(factory_name, factory, comment: nil, cacheable: true, single_match: false, cache_by: nil, allow_anonymous: false) ⇒ PolicyFactory
Returns a new instance of PolicyFactory.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sequel/privacy/policy_factory.rb', line 25 def initialize(factory_name, factory, comment: nil, cacheable: true, single_match: false, cache_by: nil, allow_anonymous: false) @factory_name = T.let(factory_name.to_s, String) @factory = T.let(factory, Proc) @comment = T.let(comment, T.nilable(String)) @cacheable = T.let(cacheable, T::Boolean) @single_match = T.let(single_match, T::Boolean) @cache_by = T.let(cache_by, T.nilable(T.any(Symbol, T::Array[Symbol]))) @allow_anonymous = T.let(allow_anonymous, T::Boolean) end |
Instance Attribute Details
#factory_name ⇒ Object (readonly)
Returns the value of attribute factory_name.
12 13 14 |
# File 'lib/sequel/privacy/policy_factory.rb', line 12 def factory_name @factory_name end |
Instance Method Details
#call(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sequel/privacy/policy_factory.rb', line 37 def call(*args) lam = T.unsafe(@factory).call(*args) unless lam.is_a?(Proc) Kernel.raise ArgumentError, "Policy factory #{@factory_name} must return a Proc, got #{lam.inspect}" end T.cast( Policy.create( policy_name_for(args), lam, @comment, cacheable: @cacheable, single_match: @single_match, cache_by: @cache_by, allow_anonymous: @allow_anonymous ), Policy ) end |