However, Dependencies overrides the require
method to keep track of the modules and classes being defined by files as they
are required. The new version of require causes problems and prevents Og??™s
dependencies from being loaded properly.
To resolve this, we temporarily disable all special require functionality while
loading Og. First, we store away a copy of the fully functional require, with
RubyGems and Dependencies, as require_with_rubygems. Then we alias gem_
original_require (the no-frills standard Ruby require, which RubyGems helpfully
aliases) as require, so that Og doesn??™t notice any of the sneaky things we
are doing. When Og is loaded, we can put the full-featured require_with_
rubygems back into place.
Notice that the actual call requiring Og needs to use require_with_rubygems so
that it will find the gem. We do all of this manipulation so that Og??™s nested calls
to require will use the Ruby version, not the RubyGems/Rails version.
3. In this example, we are mixing the Orderable module into our class; Og uses
mixins to add behavior to model classes, where ActiveRecord would conventionally
use class methods (in this example, acts_as_list). Using Module#autoload,
we designate that Og::Mixin::Orderable can be found under Og??™s source tree at
og/model/orderable.rb.
4. As mentioned before, Og needs to see all of the models when it starts, so that it
can inject them with Og model methods.
Pages:
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424