class ConventionalExtensions::Loader
def extension_path_for(extension)
def extension_path_for(extension) @directory_name + "#{extension}.rb" end
def extension_paths
def extension_paths Dir.glob extension_path_for("*") end
def initialize(klass, path)
def initialize(klass, path) @klass, @name = klass, klass.name @directory_name = File.join path.match(/(?=\/extensions|\.rb)/).pre_match, "extensions/" end
def load(*extensions)
def load(*extensions) paths = extensions.empty? ? extension_paths : extensions.map { extension_path_for _1 } paths.each { load_one _1 } end
def load_one(extension)
def load_one(extension) contents = File.read extension case when contents.match?(/\s*class #{@name}/) require extension when !$LOADED_FEATURES.include?(extension) $LOADED_FEATURES << extension @klass.class_eval contents, extension, 0 end end