Class: Orthoses::ActiveSupport::Aliasing

Inherits:
Object
  • Object
show all
Defined in:
lib/orthoses/active_support/aliasing.rb

Overview

def alias_attribute(new_name, old_name)

Instance Method Summary collapse

Constructor Details

#initialize(loader) ⇒ Aliasing

Returns a new instance of Aliasing.



7
8
9
# File 'lib/orthoses/active_support/aliasing.rb', line 7

def initialize(loader)
  @loader = loader
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/orthoses/active_support/aliasing.rb', line 11

def call
  alias_attribute = CallTracer::Lazy.new

  store =
    alias_attribute.trace('Module#alias_attribute') do
      @loader.call
    end

  alias_attribute.captures.each do |capture|
    base_mod_name = Utils.module_name(capture.method.receiver) or next
    new_name = capture.argument[:new_name]

    content = store[base_mod_name]
    # TODO: Shold use alias? But, it has risc of undefined method
    content << "def #{new_name}: () -> untyped"
    content << "def #{new_name}?: () -> bool"
    content << "def #{new_name}=: (untyped) -> untyped"
  end

  store
end