Sha256: 633d2758558a9549da5da761a95e8d69ea749229213344f6c5577f03c8909d6b

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 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(&: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 type
      :group
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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