Class: ActiveDelegate::Associations
Overview
Delegates associations to an associated model
Instance Attribute Summary
Attributes inherited from Delegator
#model, #options
Instance Method Summary
collapse
Methods inherited from Delegator
#association_class, #association_name, #association_reflection, #default_options, #delegation_args, #delegation_options, #delegation_prefix, #initialize
Instance Method Details
#association_names ⇒ Object
13
14
15
|
# File 'lib/active_delegate/associations.rb', line 13
def association_names
association_reflections.map(&:name)
end
|
#association_reflections ⇒ Object
9
10
11
|
# File 'lib/active_delegate/associations.rb', line 9
def association_reflections
association_class.reflect_on_all_associations
end
|
#call ⇒ Object
21
22
23
24
25
26
|
# File 'lib/active_delegate/associations.rb', line 21
def call
delegatable_associations.each do |association|
methods = Association::Methods.new(association, association_class)
model.delegate(*methods.delegatable, **delegation_options)
end
end
|
#delegatable_associations ⇒ Object
17
18
19
|
# File 'lib/active_delegate/associations.rb', line 17
def delegatable_associations
delegation_args(association_names)
end
|