Class: AutoCode::Loader
- Inherits:
-
Object
- Object
- AutoCode::Loader
- Defined in:
- lib/auto_code.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(cname) ⇒ Object
-
#initialize(options = {}) ⇒ Loader
constructor
A new instance of Loader.
Constructor Details
#initialize(options = {}) ⇒ Loader
Returns a new instance of Loader.
10 |
# File 'lib/auto_code.rb', line 10 def initialize(={}); @directories = [:directories] ; end |
Class Method Details
.snake_case(cname) ⇒ Object
20 21 22 |
# File 'lib/auto_code.rb', line 20 def Loader.snake_case(cname) cname.gsub(/([a-z\d])([A-Z])/){"#{$1}_#{$2}"}.tr("-", "_").downcase end |
Instance Method Details
#call(cname) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/auto_code.rb', line 11 def call(cname) if @directories.nil? Kernel.load( Loader.snake_case( cname.to_s ) << '.rb' ) else filename = Loader.snake_case( cname.to_s ) << '.rb' path = @directories.map { |dir| File.join( dir.to_s, filename ) }.find { |path| File.exist?( path ) } Kernel.load( path ) rescue nil unless path.nil? end end |