Prev | Current Page 411 | Next

Brad Ediger

"Advanced Rails"

Work around the RubyGems / Dependencies version of require
class Object
alias_method :require_with_rubygems, :require
alias_method :require, :gem_original_require
require_with_rubygems 'og'
# Restore the Dependencies require for future require calls
alias_method :require, :require_with_rubygems
end
# 3. Define autoload path so the model can find the Orderable mixin.
# This is relative to $LOAD_PATH, which includes the lib path in the og
# gem directory.
278 | Chapter 9: Incorporating and Extending Rails
Og::Mixin.autoload :Orderable, 'og/model/orderable'
# 4. Models must be loaded before Og starts
Dir[File.join(RAILS_ROOT, 'app', 'models', '*.rb')].each(&method(:load))
# 5. Read in database.yml and start Og
config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'database.yml'))
$og = Og.start(config[RAILS_ENV].symbolize_keys)
This does several things to initialize Og:
1. First, as a sanity check, we use the gem method to specify the exact gem version
we installed. As long as the gem specification (og.gemspec) specifies a version of
0.50.0, that is the version that RubyGems will recognize. Therefore, we can
refresh the Og gem from edge for minor changes without updating this line.
2. The class Object block is in place to work around an incompatibility between
Ruby Facets and Rails Dependencies. Og??™s initialization methods load methods in
Facets using the require method.


Pages:
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423