Sha256: 97597424d4171006dc517bf6252e91069589dcc30b16f5fe4a85d37b4c7dca8f
Contents?: true
Size: 820 Bytes
Versions: 5
Compression:
Stored size: 820 Bytes
Contents
require 'hovercraft/caller' require 'active_support/inflector' module Hovercraft class Loader def initialize @caller = Caller.new end def with_each_model models.each do |model_class| model_name = model_class.name.underscore plural_model_name = model_name.pluralize yield(model_class, model_name, plural_model_name) end end def models @models ||= require_models end private def require_models Dir.glob(File.join(models_directory, '**/*.rb')).map do |file| require file class_from(file) end end def models_directory File.join(@caller.directory, 'models') end def class_from(file) file.gsub!(/#{models_directory}|.rb/, '') file.classify.safe_constantize end end end
Version data entries
5 entries across 5 versions & 1 rubygems