Sha256: 360575e52ec467d22d69569e027c63b457656e0545fefb121e41a796fcf54927

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
require 'active_support'
require 'active_support/core_ext'

# Represents a source directory full of classe - e.g.,
# lib/vincelifedaily/checks/*
class DirectoryOfClasses
  attr_reader :dir, :module_name

  def initialize(dir: raise, class_suffix: '', module_name: '')
    @dir = dir
    @class_suffix = class_suffix
    @module_name = module_name
  end

  def filenames
    Dir.glob("#{dir}/**.rb").sort
  end

  def basenames
    filenames.map { |filename| File.basename(filename) }
  end

  def basenames_without_extension
    filenames.map { |filename| File.basename(filename, '.*') }
  end

  def require_classes
    basenames.each do |basename|
      path = "#{dir}/#{basename}"
      require_relative path
    end
  end

  def symbols_and_classes
    @symbols_and_classes ||= filenames.map do |filename|
      basename = File.basename(filename, '.rb')

      class_name = "#{module_name}::#{basename.camelize}#{@class_suffix}"
      clazz = class_name.constantize
      symbol = basename.to_sym
      [symbol, clazz]
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
quality-27.4.0 lib/quality/directory_of_classes.rb
quality-27.3.1 lib/quality/directory_of_classes.rb
quality-27.3.0 lib/quality/directory_of_classes.rb
quality-27.2.0 lib/quality/directory_of_classes.rb
quality-27.1.1 lib/quality/directory_of_classes.rb
quality-27.1.0 lib/quality/directory_of_classes.rb
quality-27.0.0 lib/quality/directory_of_classes.rb
quality-26.0.0 lib/quality/directory_of_classes.rb
quality-25.0.0 lib/quality/directory_of_classes.rb
quality-24.0.0 lib/quality/directory_of_classes.rb
quality-23.0.7 lib/quality/directory_of_classes.rb
quality-23.0.6 lib/quality/directory_of_classes.rb
quality-23.0.5 lib/quality/directory_of_classes.rb
quality-23.0.4 lib/quality/directory_of_classes.rb
quality-23.0.3 lib/quality/directory_of_classes.rb
quality-23.0.2 lib/quality/directory_of_classes.rb
quality-23.0.1 lib/quality/directory_of_classes.rb
quality-23.0.0 lib/quality/directory_of_classes.rb