Sha256: 9716cebfe417ff9ef94aa9f8daf9dfab7b94730c207d870f82b439208cfdf645

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

require 'active_support/inflector'
require_relative '../extensions/extensions'

module Jetel
  module Modules
    class << self
      def modules(modules_dir = File.join(File.dirname(__FILE__)), auto_require = true, require_only = false)
        dir = File.absolute_path(modules_dir)
        res = Dir.entries(dir).map do |entry|
          dir_path = File.join(dir, entry)

          next unless File.directory?(dir_path)
          next if entry == '.' || entry == '..'

          full_path = File.join(dir_path, "#{entry}.rb")
          next unless File.exist?(full_path)

          # Require file if auto_require true
          require(full_path) if auto_require

          # Go to next file if require_only mode
          next if require_only

          class_name = entry.camelize
          qualified_class_name = "Jetel::Modules::#{class_name}"

          # Return value from map iteration
          {
            name: entry,
            path: full_path,
            class_name: class_name,
            qualified_class_name: qualified_class_name,
            klass: auto_require ? Kernel.qualified_const_get(qualified_class_name) : nil
          }
        end

        # Remove nil values and return
        res.compact
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jetel-0.0.15 lib/jetel/modules/modules.rb
jetel-0.0.14 lib/jetel/modules/modules.rb
jetel-0.0.12 lib/jetel/modules/modules.rb
jetel-0.0.11 lib/jetel/modules/modules.rb
jetel-0.0.10 lib/jetel/modules/modules.rb
jetel-0.0.9 lib/jetel/modules/modules.rb
jetel-0.0.8 lib/jetel/modules/modules.rb
jetel-0.0.7 lib/jetel/modules/modules.rb
jetel-0.0.6 lib/jetel/modules/modules.rb
jetel-0.0.5 lib/jetel/modules/modules.rb
jetel-0.0.4 lib/jetel/modules/modules.rb
jetel-0.0.3 lib/jetel/modules/modules.rb