Class: Orthoses::Attribute

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

Defined Under Namespace

Modules: Hook

Constant Summary collapse

CALL_GRAPH =
{}

Instance Method Summary collapse

Constructor Details

#initialize(loader) ⇒ Attribute

Returns a new instance of Attribute.



27
28
29
30
# File 'lib/orthoses/attribute.rb', line 27

def initialize(loader)
  CALL_GRAPH.clear
  @loader = loader
end

Instance Method Details

#callObject



32
33
34
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
65
66
67
68
69
# File 'lib/orthoses/attribute.rb', line 32

def call
  ::Module.prepend(Hook)

  store = @loader.call

  CALL_GRAPH.dup.each do |base_mod, calls|
    m = base_mod.to_s.match(/#<Class:([\w:]+)>/)
    if m && m[1]
      receiver_name = m[1]
      prefix = "self."
    else
      receiver_name = Utils.module_name(base_mod) or next
      prefix = nil
    end
    content = store[receiver_name]

    calls.each do |(a, names)|
      case a
      when :attr
        if names[1].equal?(true)
          content << "attr_accessor #{prefix}#{names[0]}: untyped"
        elsif names[1].equal?(false)
          content << "attr_reader #{prefix}#{names[0]}: untyped"
        else
          names.each do |name|
            content << "attr_reader #{prefix}#{name}: untyped"
          end
        end
      else
        names.each do |name|
          content << "#{a} #{prefix}#{name}: untyped"
        end
      end
    end
  end

  store
end