Module: Cattri

Defined in:
lib/cattri.rb,
lib/cattri/dsl.rb,
lib/cattri/error.rb,
lib/cattri/context.rb,
lib/cattri/version.rb,
lib/cattri/attribute.rb,
lib/cattri/visibility.rb,
lib/cattri/introspection.rb,
lib/cattri/internal_store.rb,
lib/cattri/context_registry.rb,
lib/cattri/attribute_options.rb,
lib/cattri/initializer_patch.rb,
lib/cattri/attribute_compiler.rb,
lib/cattri/attribute_registry.rb,
lib/cattri/deferred_attributes.rb

Overview

Main entrypoint for the Cattri DSL.

When included in a class or module, this installs both class-level and instance-level attribute handling logic, visibility tracking, subclass inheritance propagation, and default value enforcement.

It supports:

  • Defining class or instance attributes using ‘cattri` or `final_cattri`

  • Visibility tracking and method scoping

  • Write-once semantics for ‘final: true` attributes

  • Safe method generation with introspection support

Defined Under Namespace

Modules: ClassMethods, ContextRegistry, DeferredAttributes, Dsl, InitializerPatch, InternalStore, Introspection, Visibility Classes: Attribute, AttributeCompiler, AttributeError, AttributeOptions, AttributeRegistry, AttributeValue, Context, Error

Constant Summary collapse

VERSION =

:nocov:

"0.2.4"

Class Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method returns an undefined value.

Sets up the Cattri DSL on the including class or module.

Includes internal storage and registry infrastructure into both the base and its singleton class, prepends initialization logic, extends visibility and DSL handling, and installs the subclassing hook to propagate attributes to descendants.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cattri.rb', line 31

def self.included(base)
  [base, base.singleton_class].each do |mod|
    mod.include(Cattri::InternalStore)
    mod.include(Cattri::ContextRegistry)
    mod.instance_variable_set(:@__cattri_base_target, base)
  end

  base.extend(Cattri::InternalStore)
  base.singleton_class.extend(Cattri::InternalStore)

  base.prepend(Cattri::InitializerPatch)
  base.extend(Cattri::Visibility)
  base.extend(Cattri::Dsl)
  base.extend(ClassMethods)
end