Module: Ork::Utils
- Defined in:
- lib/ork/utils.rb
Overview
Instead of monkey patching Kernel or trying to be clever, it’s best to confine all the helper methods in a Utils module.
Class Method Summary collapse
-
.const(context, name) ⇒ Object
Used by: ‘attribute`, `reference`, `collection`.
Class Method Details
.const(context, name) ⇒ Object
Used by: ‘attribute`, `reference`, `collection`.
Employed as a solution to avoid ‘NameError` problems when trying to load models referring to other models not yet loaded.
Example:
class Comment
include Ork::Document
reference :user, User # NameError undefined constant User.
end
Instead of relying on some clever `const_missing` hack, we can
simply use a Symbol.
class Comment
include Ork::Document
reference :user, :User
end
28 29 30 31 32 33 34 |
# File 'lib/ork/utils.rb', line 28 def self.const(context, name) case name when Symbol then context.const_get(name) when String then context.const_get(name.to_sym) else name end end |