Sha256: 102bdbd4097c5d9c4473227cdc6b0aa47612805992c1f1ba8122103b773f487f

Contents?: true

Size: 976 Bytes

Versions: 14

Compression:

Stored size: 976 Bytes

Contents

#note this has been loading some namespaces twice in some cases, so dont use me yet.
module Trax
  module Core
    module EagerAutoloadNamespace
      def self.extended(base)
        source_file_path = caller[0].partition(":")[0]

        base.module_eval do
          @eager_autoload_filepath = source_file_path
        end
      end

      def all
        @all ||= autoload_class_names.map do |klass|
          const_get(:"#{klass}")
        end
      end

      def autoload_file_paths
        @autoload_file_paths = ::Dir[module_path.join('*.rb')]
      end

      def autoload_class_names
        @autoload_class_names = autoload_file_paths.map do |path|
          ::File.basename(path.to_s).split(".rb").shift.try(:classify)
        end
      end

      def eager_autoload_filepath
        @eager_autoload_filepath
      end

      def module_path
        @module_path ||= ::Pathname.new(::File.path(eager_autoload_filepath).gsub(".rb", ""))
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
trax_core-0.0.86 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.85 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.84 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.83 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.82 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.81 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.80 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.79 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.78 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.77 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.76 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.74 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.73 lib/trax/core/eager_autoload_namespace.rb
trax_core-0.0.72 lib/trax/core/eager_autoload_namespace.rb