lib/sugar-high/class_ext.rb in sugar-high-0.4.9.5 vs lib/sugar-high/class_ext.rb in sugar-high-0.5.0

- old
+ new

@@ -12,32 +12,51 @@ extend main_module.const_get(options[:class_methods]) if main_module.const_defined?(options[:class_methods]) end def autoload_modules *args - options = args.extract_options! + options = args.extract_options! root = options[:root] || AutoLoader.root || '' path = root.strip.empty? ? self.name.to_s.underscore : [root, self.name.to_s.underscore].join('/') from = options[:from] || path # Here also could be adding of the file in top of load_paths like: $:.unshift File.dirname(__FILE__) # It is very useful for situations of having not load_paths built Rails or Gems way. - args.each do |req_name| - send :autoload, req_name, "#{from}/#{req_name.to_s.underscore}" + args.each do |req_name| + ruby_file = req_name.to_s.underscore + + send :autoload, req_name, AutoLoader.translate("#{from}/#{ruby_file}") end end end module AutoLoader @@root = '' + @@namespaces = {} def self.root @@root end - def self.root= root_dir - @@root = root_dir + def self.namespaces + @@namespaces + end + + def self.root= root + @@root = root + end + + def self.namespaces= namespaces + @@namespaces = namespaces + end + + def self.translate name + names = name.split('/') + names.map do |name| + clazz_name = name.to_s.camelize + namespaces[clazz_name.to_sym] ? namespaces[clazz_name.to_sym] : name + end.join('/') end end module ClassExt def get_module name