class Object
Constants
- ContentType
Just a short-cut to make the code read nicer…
Public Instance Methods
Nuggets(*nuggets)
click to toggle source
Load selected nuggets
.
Examples:
# All String nuggets Nuggets(:string) Nuggets(String) # Only 'msub' and 'word_wrap' String nuggets Nuggets(string: %w[msub word_wrap]) # Selected String nuggets and all Numeric nuggets Nuggets(:numeric, string: %w[msub word_wrap]) # etc.
# File lib/nuggets.rb 41 def Nuggets(*nuggets) 42 loaded_nuggets, load_nuggets = [], lambda { |base, *nuggets| 43 nuggets_by_hierarchy = nuggets.last.is_a?(Hash) ? nuggets.pop : {} 44 45 nuggets.each { |nugget| 46 begin 47 require path = File.join(base.to_s, nugget.to_s.downcase) 48 loaded_nuggets << path 49 rescue LoadError 50 # if it's a directory, load anything in it 51 $LOAD_PATH.each { |dir| 52 if File.directory?(dir_path = File.join(dir, path)) 53 load_nuggets[path, *Dir[File.join(dir_path, '*')].map { |file| 54 File.basename(file, '.rb') unless file.end_with?('_mixin.rb') 55 }.compact] 56 break 57 end 58 } and raise # otherwise, re-raise 59 end 60 } 61 62 nuggets_by_hierarchy.each { |hierarchy, nuggets| 63 nuggets = [nuggets] if nuggets.is_a?(Hash) 64 load_nuggets[File.join(base.to_s, hierarchy.to_s.downcase), *nuggets] 65 } 66 } 67 68 load_nuggets['nuggets', *nuggets] 69 70 loaded_nuggets 71 end