15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/activerecord/chemistry/extendable/relation.rb', line 15
def extends(name, scope = nil, options = {})
if Hash === scope
options = scope
scope = nil
end
options[:dependent] ||= :nullify
reflections = has_one(name, scope, options)
default_scope -> { includes(name) }
validate :extendable_must_be_valid
cattr_reader(:extendable_reflection) { reflections.stringify_keys[name.to_s] }
cattr_reader(:extendable_model) { (options[:class_name] || name.to_s.camelize).constantize }
class_eval "def #{name}; super || build_#{name}(extendable_model.extended_by_reflection.name => self); end"
alias_method :extendable, name
alias_method :extendable=, "#{name}=".to_sym
include Extendable::InstanceMethods
end
|