Module: Ivar::CheckPolicy
- Defined in:
- lib/ivar/check_policy.rb
Overview
Module for adding instance variable check policy configuration to classes. This module provides a way to set and inherit check policies for instance variables. When extended in a class, it allows setting a class-specific policy that overrides the global Ivar policy.
Instance Method Summary collapse
-
#inherited(subclass) ⇒ Object
Ensure subclasses inherit the check policy from their parent This method is called automatically when a class is inherited.
-
#ivar_check_policy(policy = nil, **options) ⇒ Symbol, Policy
Set or get the check policy for this class.
Instance Method Details
#inherited(subclass) ⇒ Object
Ensure subclasses inherit the check policy from their parent This method is called automatically when a class is inherited
24 25 26 27 |
# File 'lib/ivar/check_policy.rb', line 24 def inherited(subclass) super subclass.instance_variable_set(:@__ivar_check_policy, @__ivar_check_policy) end |
#ivar_check_policy(policy = nil, **options) ⇒ Symbol, Policy
Set or get the check policy for this class
13 14 15 16 17 18 19 |
# File 'lib/ivar/check_policy.rb', line 13 def ivar_check_policy(policy = nil, **) if policy.nil? @__ivar_check_policy || Ivar.check_policy else @__ivar_check_policy = .empty? ? policy : [policy, ] end end |