Module: Polyamorous::JoinDependencyExtensions::ClassMethods

Defined in:
lib/polyamorous/activerecord_4.2_ruby_2/join_dependency.rb,
lib/polyamorous/activerecord_4.2_ruby_1.9/join_dependency.rb

Instance Method Summary collapse

Instance Method Details

#walk_tree(associations, hash) ⇒ Object

Prepended before ActiveRecord::Associations::JoinDependency#self.walk_tree



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/polyamorous/activerecord_4.2_ruby_2/join_dependency.rb', line 84

def walk_tree(associations, hash)
  case associations
  when TreeNode
    associations.add_to_tree(hash)
  when Hash
    associations.each do |k, v|
      cache =
        case k
        when TreeNode
          k.add_to_tree(hash)
        else
          hash[k] ||= {}
        end
      walk_tree(v, cache)
    end
  else
    super(associations, hash)
  end
end

#walk_tree_with_polymorphism(associations, hash) ⇒ Object

Replaces ActiveRecord::Associations::JoinDependency#self.walk_tree



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/polyamorous/activerecord_4.2_ruby_1.9/join_dependency.rb', line 73

def walk_tree_with_polymorphism(associations, hash)
  case associations
  when TreeNode
    associations.add_to_tree(hash)
  when Hash
    associations.each do |k, v|
      cache =
      case k
      when TreeNode
        k.add_to_tree(hash)
      else
        hash[k] ||= {}
      end
      walk_tree(v, cache)
    end
  else
    walk_tree_without_polymorphism(associations, hash)
  end
end