Module: Netzke::Core::Inheritance::ClassMethods

Defined in:
lib/netzke/core/inheritance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#called_fromObject

Returns the value of attribute called_from



6
7
8
# File 'lib/netzke/core/inheritance.rb', line 6

def called_from
  @called_from
end

Instance Method Details

#inherited(base) ⇒ Object

Keep track of component's file. Inspired by Rails railties code.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/netzke/core/inheritance.rb', line 18

def inherited(base)
  base.called_from = begin
    cllr = if Kernel.respond_to?(:caller_locations)
      location = caller_locations.first
      location.absolute_path || location.path
    else
      caller.first.sub(/:\d+.*/, '')
    end

    cllr[0..-4]
  end
end

#netzke_ancestorsObject

Ancestor classes in the Netzke class hierarchy up to (and excluding) Netzke::Base, including self; in comparison to Ruby's own Class.ancestors, the order is reversed.



9
10
11
12
13
14
15
# File 'lib/netzke/core/inheritance.rb', line 9

def netzke_ancestors
  if self == Netzke::Base
    []
  else
    superclass.netzke_ancestors + [self]
  end
end