Sha256: dcd316d032f5d755820b481b9c8a2260dbad2abaea1b9d8d0d2add287a006ed6
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
module AutoLoader module ClassMethods attr_writer :default_mode def root @root ||= '' end def root= root raise ArgumentError, "Must be a String, was: #{root}" if !root.kind_of?(String) @root = root end def namespaces @namespaces ||= {} end def namespaces= namespaces raise ArgumentError, "Must be a Hash, was: #{namespaces}" if !namespaces.kind_of?(Hash) @namespaces = namespaces end def mode @mode || default_mode end def mode= mode @mode = mode if valid_mode? mode end def valid_mode? mode valid_modes.include? mode end def valid_modes [:autoload, :require] end def default_mode valid_modes.first end end extend ClassMethods def self.translate name, options = {} names = name.split('/') ns = namespaces.merge(options[:namespaces] || options[:ns] || {}) names.map do |name| clazz_name = name.to_s.camelize folder = ns[clazz_name.to_sym] ? ns[clazz_name.to_sym] : name folder.sub /\/$/, '' end.join('/') end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sweetloader-0.1.4 | lib/sweetloader/auto_loader.rb |