Sha256: 0aa85aafaf5a38a073440f1f54571108deeef6fb7352f5243cbbcefbeb1cf701

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module Lookbook
  # Represents a group of preview scenarios within a preview class
  #
  # @ignore methods
  # @api public
  class ScenarioGroupEntity < Entity
    include NavigableEntity

    attr_reader :scenarios, :preview

    def initialize(name, scenarios, preview)
      @name = Utils.name(name)
      @scenarios = ScenarioCollection.new(scenarios)
      @preview = preview
      @lookup_path = "#{parent.lookup_path}/#{@name}"
    end

    def display_options
      merged = {}
      scenarios.to_a.reverse.map do |scenario|
        merged.merge!(scenario.display_options)
      end
      merged
    end

    def render_targets
      @_render_targets ||= RenderTargetCollection.new(scenarios.flat_map(&:render_targets).uniq(&:lookup_path))
    end

    def search_terms
      [parent.label, label]
    end

    def tags(tag_name = nil)
      scenarios.flat_map { |scenario| scenario.tags(tag_name) }
    end

    def tag(tag_name = nil)
      tags(tag_name).first
    end

    def url_path
      lookbook_inspect_path(lookup_path)
    end

    def preview_path
      lookbook_preview_path(lookup_path)
    end

    def type
      :group
    end

    alias_method :parent, :preview
    alias_method :components, :render_targets
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lookbook-2.0.0.beta.3 lib/lookbook/entities/scenario_group_entity.rb
lookbook-2.0.0.beta.2 lib/lookbook/entities/scenario_group_entity.rb