Sha256: be76a0ecd01aa54800a1d9f8302a2472cbd381320ced49630ffae48cc9676113
Contents?: true
Size: 1.02 KB
Versions: 9
Compression:
Stored size: 1.02 KB
Contents
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
9 entries across 9 versions & 1 rubygems