Sha256: e87690c03203042d45eea4117caeaedc2896a196b45339a761ffc35109a58d22

Contents?: true

Size: 948 Bytes

Versions: 1

Compression:

Stored size: 948 Bytes

Contents

module Netzke
  module Core
    module Inheritance
      extend ActiveSupport::Concern
      module ClassMethods
        attr_accessor :called_from

        # 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.
        def netzke_ancestors
          if self == Netzke::Base
            []
          else
            superclass.netzke_ancestors + [self]
          end
        end

        # Keep track of component's file. Inspired by Rails railties code.
        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
            end

            cllr.split(".rb").first
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
netzke-core-1.0.0.0.pre lib/netzke/core/inheritance.rb