Module: SweetLoader::ClassMethods
- Included in:
- SweetLoader
- Defined in:
- lib/sweetloader/class_methods.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #mode ⇒ Object
- #mode=(mode) ⇒ Object
- #namespaces ⇒ Object
- #namespaces=(namespaces) ⇒ Object
- #root ⇒ Object
- #root=(root) ⇒ Object
- #translate(name, options = {}) ⇒ Object
- #valid_mode?(mode) ⇒ Boolean
- #valid_modes ⇒ Object
Instance Attribute Details
#default_mode ⇒ Object
49 50 51 |
# File 'lib/sweetloader/class_methods.rb', line 49 def default_mode valid_modes.first end |
Instance Method Details
#mode ⇒ Object
33 34 35 |
# File 'lib/sweetloader/class_methods.rb', line 33 def mode @mode || default_mode end |
#mode=(mode) ⇒ Object
37 38 39 |
# File 'lib/sweetloader/class_methods.rb', line 37 def mode= mode @mode = mode if valid_mode? mode end |
#namespaces ⇒ Object
24 25 26 |
# File 'lib/sweetloader/class_methods.rb', line 24 def namespaces @namespaces ||= {} end |
#namespaces=(namespaces) ⇒ Object
28 29 30 31 |
# File 'lib/sweetloader/class_methods.rb', line 28 def namespaces= namespaces raise ArgumentError, "Must be a Hash, was: #{namespaces}" if !namespaces.kind_of?(Hash) @namespaces = namespaces end |
#root ⇒ Object
15 16 17 |
# File 'lib/sweetloader/class_methods.rb', line 15 def root @root ||= '' end |
#root=(root) ⇒ Object
19 20 21 22 |
# File 'lib/sweetloader/class_methods.rb', line 19 def root= root raise ArgumentError, "Must be a String, was: #{root}" if !root.kind_of?(String) @root = root end |
#translate(name, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/sweetloader/class_methods.rb', line 5 def translate name, = {} names = name.split('/') ns = namespaces.merge([:namespaces] || [: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 |
#valid_mode?(mode) ⇒ Boolean
41 42 43 |
# File 'lib/sweetloader/class_methods.rb', line 41 def valid_mode? mode valid_modes.include? mode end |
#valid_modes ⇒ Object
45 46 47 |
# File 'lib/sweetloader/class_methods.rb', line 45 def valid_modes [:autoload, :require] end |