1
0

Added Target create action

This commit is contained in:
cryptogopher
2020-07-25 16:28:55 +02:00
parent 5b83860ed7
commit ffcc9553d5
12 changed files with 154 additions and 66 deletions

View File

@@ -2,21 +2,31 @@ module BodyTracking::AwesomeNestedSetPatch
CollectiveIdea::Acts::NestedSet.class_eval do
module CollectiveIdea::Acts::NestedSet
class Iterator
def each_with_path
def each_with_ancestors
return to_enum(__method__) { objects.length } unless block_given?
path = [nil]
ancestors = [nil]
objects.each do |o|
path[path.rindex(o.parent)+1..-1] = o
yield [o, path.map { |q| q.try(:name) }.join('::')]
ancestors[ancestors.rindex(o.parent)+1..-1] = o
yield ancestors
end
end
end
module Model
module ClassMethods
def each_with_path(objects, &block)
Iterator.new(objects).each_with_path(&block)
def each_with_path(objects)
return to_enum(__method__, objects) { objects.length } unless block_given?
Iterator.new(objects).each_with_ancestors do |ancestors|
yield [ancestors.last, ancestors.map { |q| q.try(:name) }.join('::')]
end
end
def each_with_ancestors(objects)
return to_enum(__method__, objects) { objects.length } unless block_given?
Iterator.new(objects).each_with_ancestors { |ancestors| yield ancestors.dup }
end
end
end