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-2.0.0 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.rc.3 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.5.5 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.5.4 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.rc.2 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.rc.1 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.9 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.8 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.7 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.6 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.5 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.4 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.3 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.2 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.5.3 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.1 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.5.2 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-2.0.0.beta.0 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.5.1 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb
lookbook-1.5.0 lib/lookbook/entities/collections/concerns/hierarchical_collection.rb