Module: LowType

Defined in:
lib/low_type.rb,
lib/syntax/syntax.rb

Overview

Architecture: ┌────────┐ ┌─────────┐ ┌─────────────┐ ┌─────────┐ ┌─────────┐│ Lowkey │ │ Proxies │ │ Expressions │ │ LowType │ │ Methods │└────┬───┘ └────┬────┘ └──────┬──────┘ └────┬────┘ └────┬────┘

                                                               
 Parses AST                                                    
├─────────────►│                                                 
                                                               
               Stores                                          
              ├────────────────►│                                
                                                               
                                Evaluates                      
                               │◄────────────────┤               
                                                               
                                                 Redefines     
                                                ├──────────────►│
                                                               
                                Validates                      
                               │◄┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┤
                                                               

Defined Under Namespace

Modules: Syntax

Class Method Summary collapse

Class Method Details

.configObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/low_type.rb', line 67

def config
  config = Struct.new(
    :type_checking,
    :error_mode,
    :output_mode,
    :output_size,
    :deep_type_check,
    :union_type_expressions
  )
  @config ||= config.new(true, :error, :type, 100, true, true)
end

.configure {|config| ... } ⇒ Object

Yields:



79
80
81
# File 'lib/low_type.rb', line 79

def configure
  yield(config)
end

.included(klass) ⇒ Object

Defers evaluation and redefinition until after the class body finishes loading via TracePoint :end.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/low_type.rb', line 35

def self.included(klass)
  file_path = Low::FileQuery.file_path(klass:)
  file_proxy = Lowkey.load(file_path)
  class_proxy = file_proxy[klass.name]

  klass.include Low::ExpressionHelpers
  klass.extend Low::ExpressionHelpers
  klass.extend Low::TypeAccessors
  klass.extend Low::Types

  # Use TracePoint :end to capture the class binding after the class body finishes loading.
  # At :end time, trace.self is the including class and trace.binding is the class body's binding,
  # stored on class_proxy.class_binding for use by LowType and other consumers.
  tp = TracePoint.new(:end) do |trace|
    next unless trace.self == klass

    class_proxy.class_binding = trace.binding

    Low::Evaluator.evaluate(method_proxies: class_proxy.keyed_methods)

    klass.prepend Low::Redefiner.redefine(method_proxies: class_proxy.instance_methods, class_proxy:)
    klass.singleton_class.prepend Low::Redefiner.redefine(method_proxies: class_proxy.class_methods, class_proxy:)

    Low::Adapter::Loader.load(klass:, class_proxy:)

    tp.disable
  end

  tp.enable
end