Module: Finalist::ModuleMethods

Defined in:
lib/finalist.rb

Instance Method Summary collapse

Instance Method Details

#extended(base) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/finalist.rb', line 58

def extended(base)
  def base.singleton_method_added(symbol)
    super

    meth = singleton_class.instance_method(symbol)
    super_method = meth.super_method
    while super_method
      if Finalist.finalized_methods[super_method.owner]&.member?(super_method.name)
        raise OverrideFinalMethodError.new("#{super_method} at #{super_method.source_location.join(":")} is overrided\n  by #{meth} at #{meth.source_location.join(":")}", singleton_class, super_method.owner, meth, :extended_singleton_method_added)
      end
      super_method = super_method.super_method
    end
  end

  base.singleton_class.ancestors.drop(1).each do |mod|
    Finalist.finalized_methods[mod]&.each do |fmeth_name|
      if meth = base.singleton_class.instance_method(fmeth_name)
        super_method = meth.super_method
        while super_method
          if Finalist.finalized_methods[super_method.owner]&.member?(super_method.name)
            raise OverrideFinalMethodError.new("#{super_method} at #{super_method.source_location.join(":")} is overrided\n  by #{meth} at #{meth.source_location.join(":")}", base.singleton_class, super_method.owner, meth, :extended)
          end
          super_method = super_method.super_method
        end
      end
    end
  end
end

#included(base) ⇒ Object



29
30
31
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
# File 'lib/finalist.rb', line 29

def included(base)
  super

  base.extend(Finalist)

  caller_info = caller_locations(1, 2).last
  event_type =
    if caller_info.label.match?(/block/)
      :b_return
    else
      :end
    end

  base.ancestors.drop(1).each do |mod|
    Finalist.finalized_methods[mod]&.each do |fmeth_name|
      if meth = base.instance_method(fmeth_name)
        super_method = meth.super_method
        while super_method
          if Finalist.finalized_methods[super_method.owner]&.member?(super_method.name)
            raise OverrideFinalMethodError.new("#{super_method} at #{super_method.source_location.join(":")} is overrided\n  by #{meth} at #{meth.source_location.join(":")}", base, super_method.owner, meth, :included)
          end

          super_method = super_method.super_method
        end
      end
    end
  end
end