Module: Ivar::Checked

Defined in:
lib/ivar/checked.rb,
lib/ivar/checked/class_methods.rb,
lib/ivar/checked/instance_methods.rb

Overview

Provides automatic validation for instance variables. When included in a class, this module:

  1. Automatically calls check_ivars after initialization

  2. Extends the class with CheckPolicy for policy configuration

  3. Extends the class with Macros for ivar declarations

  4. Sets a default check policy of :warn

  5. Handles proper inheritance of these behaviors in subclasses

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

When this module is included in a class, it extends the class with ClassMethods and includes the Validation module

Parameters:

  • base (Class)

    The class that is including this module



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ivar/checked.rb', line 21

def self.included(base)
  base.include(Validation)
  base.extend(ClassMethods)
  base.extend(CheckPolicy)
  base.extend(Macros)
  base.prepend(InstanceMethods)

  # Set default policy for Checked to :warn
  # This can be overridden by calling ivar_check_policy in the class
  base.ivar_check_policy(Ivar.check_policy)
end