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
-
#easyload_root ⇒ Object
readonly
The root path that easyload should use when loading a child constant for this module.
Instance Method Summary collapse
-
#easyload_from(root_path) ⇒ Object
Sets easyload_root.
-
#easyload_path_component_for_sym(sym) ⇒ Object
Converts a CamelCased symbol into a path component.
Instance Attribute Details
#easyload_root ⇒ Object (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
Singlesymbol becomessingle. -
MultiWordSymbolsbecomemulti_word_symbols. -
ACRONYMSare treated like words:acronyms. -
ABCFoois 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 |