Class: Hecks::Bluebook::DSL::ConstShim::ScopedConstant

Inherits:
Module
  • Object
show all
Defined in:
lib/hecks/bluebook/dsl/const_shim.rb

Overview

THE SCOPED-CONSTANT BRIDGE (ADR 0025, docs/dsl-work-slices.md's S0b) — a Symbol cannot answer ::, so Account::Debit and admits: Account::LedgerDirection could never resolve past their FIRST segment while Account returned a bare Symbol (resolver = ->(const) { const }, bluebook_builder.rb's own comment on why that was right for a BARE name): Ruby's :: operator raises TypeError on the returned value before any DSL code runs at all, unless that value is itself a Module.

A REAL Module subclass, not a decorated Symbol, for exactly that reason — nothing else answers ::. Every existing consumer keeps working duck-typed, not because nothing changed: Attribute#spell's type.is_a?(Module) branch now fires where it used to fall to type.to_s, and Naming.demodulise (path.split("::").last) gives the IDENTICAL string either way for a single segment — the two branches were already equivalent for a name with no :: in it, which is every bareword before this.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ScopedConstant

Returns a new instance of ScopedConstant.



40
41
42
43
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 40

def initialize(path)
  super()
  @path = path
end

Class Method Details

.for(path) ⇒ Object



38
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 38

def self.for(path) = new(path.to_s)

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



57
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 57

def ==(other) = other.is_a?(ScopedConstant) ? @path == other.hecks_path : @path.to_sym == other

#const_missing(name) ⇒ Object

ONE MORE SEGMENT, the same way an unresolved const anywhere else does — Account::Debit::Anything keeps chaining rather than refusing, since nothing here knows how deep a reference is meant to go; the DSL keyword that finally reads .to_s is the one place that does.



50
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 50

def const_missing(name) = ScopedConstant.for("#{@path}::#{name}")

#hashObject



59
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 59

def hash = @path.hash

#hecks_pathObject



55
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 55

def hecks_path = @path

#inspectObject



54
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 54

def inspect  = @path

#to_sObject



52
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 52

def to_s     = @path

#to_symObject



53
# File 'lib/hecks/bluebook/dsl/const_shim.rb', line 53

def to_sym   = @path.to_sym