Module: Easyload::SingletonExtensions

Defined in:
lib/easyload/singleton_extensions.rb

Overview

The singleton methods that are defined for a module that includes Easyload.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#easyload_rootObject (readonly)

The root path that easyload should use when loading a child constant for this module.

Defaults to the path component form of the class/module’s name



13
14
15
# File 'lib/easyload/singleton_extensions.rb', line 13

def easyload_root
  @easyload_root
end

Instance Method Details

#easyload_from(root_path) ⇒ Object

Sets easyload_root.



16
17
18
# File 'lib/easyload/singleton_extensions.rb', line 16

def easyload_from(root_path)
  @easyload_root = root_path.to_s
end

#easyload_path_component_for_sym(sym) ⇒ Object

Converts a CamelCased symbol into a path component.

  • A Single symbol becomes single.

  • MultiWordSymbols become multi_word_symbols.

  • ACRONYMS are treated like words: acronyms.

  • ABCFoo is considered to be a mix of acronyms and words: abc_foo.



26
27
28
29
30
31
32
33
# File 'lib/easyload/singleton_extensions.rb', line 26

def easyload_path_component_for_sym(sym)
  path = sym.to_s.dup
  path.gsub!(/([A-Z]+)([A-Z][a-z]+)/, '\1_\2_')
  path.gsub!(/([A-Z][a-z]+)/, '\1_')
  path.gsub!(/_+/, '_')
  path.chomp!('_')
  path.downcase!
end