Class: ArLazyPreload::AssociationTreeBuilder
- Inherits:
-
Object
- Object
- ArLazyPreload::AssociationTreeBuilder
- Defined in:
- lib/ar_lazy_preload/association_tree_builder.rb
Overview
This class is responsible for building association subtrees from a given association tree For instance, given a following tree ‘[:users, { users: :comments }]`, #subtree_for will build a subtree `[:comments]` when :users argument is passed
Instance Attribute Summary collapse
-
#association_tree ⇒ Object
readonly
Returns the value of attribute association_tree.
Instance Method Summary collapse
-
#initialize(association_tree) ⇒ AssociationTreeBuilder
constructor
A new instance of AssociationTreeBuilder.
- #subtree_for(association) ⇒ Object
Constructor Details
#initialize(association_tree) ⇒ AssociationTreeBuilder
Returns a new instance of AssociationTreeBuilder.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ar_lazy_preload/association_tree_builder.rb', line 10 def initialize(association_tree) @association_tree = case association_tree when Array association_tree when Hash [association_tree] else raise ArgumentError, "unexpected association_tree with class #{association_tree.class}" end.select { |node| node.is_a?(Hash) } end |
Instance Attribute Details
#association_tree ⇒ Object (readonly)
Returns the value of attribute association_tree.
8 9 10 |
# File 'lib/ar_lazy_preload/association_tree_builder.rb', line 8 def association_tree @association_tree end |
Instance Method Details
#subtree_for(association) ⇒ Object
22 23 24 |
# File 'lib/ar_lazy_preload/association_tree_builder.rb', line 22 def subtree_for(association) subtree_cache[association] end |