Sha256: 5ca51935e57e42a15e099dcd4269bf07288c0740b31470dba002f457e96a2fe7

Contents?: true

Size: 649 Bytes

Versions: 25

Compression:

Stored size: 649 Bytes

Contents

module Lookbook
  module HierarchicalCollection
    extend ActiveSupport::Concern

    included do
      def entities
        @_cache[:entities] ||= collect_ordered_entities(to_tree(include_hidden: true))
      end

      def to_tree(include_hidden: false)
        @_cache[include_hidden ? :tree_with_hidden : :tree] ||= EntityTreeBuilder.call(@entities, include_hidden: include_hidden)
      end

      protected

      def collect_ordered_entities(start_node)
        start_node.inject([]) do |entities, node|
          entities.append(node.content? ? node.content : collect_ordered_entities(node))
        end.flatten
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
lookbook-1.4.5 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.4.4 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.4.3 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.4.2 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.4.1 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb