Method: Spider::App::ClassMethods#req

Defined in:
lib/spiderfw/app.rb

#req(*list) ⇒ nil Also known as: app_require

Require files inside the App’s path

Can accept either a list of files to require, relative to the app’s path; or, a Hash containing arrays for keys corresponding to folders inside app (e.g. :models, :controllers)

If an Hash is provided, will load files in the order :lib, :models, :widgets, :controllers, followed by any additional keys, in the order they are defined in the Hash (under Ruby 1.9.x), or in random order (Ruby 1.8.x)

Parameters:

  • files (Hash|file1, file2, ...)

    to require

Returns:

  • (nil)


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/spiderfw/app.rb', line 277

def req(*list)
    do_require = Proc.new{ |f| 
        Kernel.require File.join(@path, f) 
    }
    if list.first.is_a?(Hash)
        hash = list.first
        load_keys = ([:lib, :models, :widgets, :controllers] + hash.keys).uniq
        load_keys.each do |k|
            if hash[k].is_a?(Array)
                hash[k].each{ |file| 
                    if k == :widgets
                        file = File.join(file, file)
                    end
                    file = File.join(k.to_s, file)
                    do_require.call(file) 
                }
            end
        end
    else
        list.each do |file|
            do_require.call(file)
        end
    end
end