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

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

Parameters:

  • subclass (Class)

    The subclass that is inheriting from this class



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

Parameters:

  • policy (Symbol, Policy) (defaults to: nil)

    The check policy to set

  • options (Hash)

    Additional options for the policy

Returns:

  • (Symbol, Policy)

    The current check policy



13
14
15
16
17
18
19
# File 'lib/ivar/check_policy.rb', line 13

def ivar_check_policy(policy = nil, **options)
  if policy.nil?
    @__ivar_check_policy || Ivar.check_policy
  else
    @__ivar_check_policy = options.empty? ? policy : [policy, options]
  end
end