Top Level Namespace
Defined Under Namespace
Modules: Dragonfly Classes: Array, Hash, Object, String, Symbol
Instance Method Summary collapse
- #autoload_files_in_dir(path, namespace) ⇒ Object
-
#camelize(path) ⇒ Object
The convention is that dirs are modules so declare them here and autoload any modules/classes inside them All paths here are absolute.
Instance Method Details
#autoload_files_in_dir(path, namespace) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dragonfly.rb', line 15 def autoload_files_in_dir(path, namespace) # Define the module eval("module #{namespace}; end") # Autoload modules/classes in that module Dir.glob("#{path}/*.rb").each do |file| file = File.(file) sub_const_name = camelize( File.basename(file, '.rb') ) eval("#{namespace}.autoload('#{sub_const_name}', '#{file}')") end # Recurse on subdirectories Dir.glob("#{path}/*/").each do |dir| sub_namespace = camelize( File.basename(dir) ) autoload_files_in_dir(dir, "#{namespace}::#{sub_namespace}") end end |
#camelize(path) ⇒ Object
The convention is that dirs are modules so declare them here and autoload any modules/classes inside them All paths here are absolute
6 7 8 9 10 11 12 13 14 |
# File 'lib/dragonfly.rb', line 6 def camelize(path) # e.g. 'test/this_one' => Test::ThisOne "#{path}". chomp('/'). gsub('/','::'). gsub(/([^a-z])(\w)/){ "#{$1}#{$2.upcase}" }. gsub('_',''). sub(/^(\w)/){ $1.upcase } end |