Class: ActiveDelegate::Associations

Inherits:
Delegator
  • Object
show all
Defined in:
lib/active_delegate/associations.rb

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

Constructor Details

This class inherits a constructor from ActiveDelegate::Delegator

Instance Method Details

#association_namesObject



13
14
15
# File 'lib/active_delegate/associations.rb', line 13

def association_names
  association_reflections.map(&:name)
end

#association_reflectionsObject



9
10
11
# File 'lib/active_delegate/associations.rb', line 9

def association_reflections
  association_class.reflect_on_all_associations
end

#callObject



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_associationsObject



17
18
19
# File 'lib/active_delegate/associations.rb', line 17

def delegatable_associations
  delegation_args(association_names)
end