Class: Lookbook::ScenarioGroupEntity
- Includes:
- NavigableEntity
- Defined in:
- lib/lookbook/entities/scenario_group_entity.rb
Overview
Represents a group of preview scenarios within a preview class
Scenarios collapse
-
#scenarios ⇒ Array<ScenarioEntity>
readonly
Returns all scenarios within the group.
Instance Attribute Summary collapse
-
#preview ⇒ PreviewEntity
(also: #parent)
readonly
The preview that this scenario belongs to.
Display options collapse
-
#display_options ⇒ Hash
Display options hash.
Render Targets collapse
-
#render_targets ⇒ Array<RenderableEntity>
(also: #components)
Collection of render targets (components or partials) from each of the scenarios in the group.
Annotations collapse
- #tag(tag_name = nil) ⇒ Object private
-
#tags(tag_name = nil) ⇒ Array<YardTag>
Collection of tags from each of the scenarios in the group.
URLs collapse
-
#inspect_path ⇒ String
(also: #url_path)
The inspector URL path for this scenario group.
-
#preview_path ⇒ String
The standalone preview URL path for this scenario group.
Identity collapse
-
#type ⇒ Symbol
Entity type identifier.
Instance Method Summary collapse
- #add_scenario(scenario) ⇒ Object private
-
#initialize(name, scenarios, preview) ⇒ ScenarioGroupEntity
constructor
private
A new instance of ScenarioGroupEntity.
- #search_terms ⇒ Object private
Methods inherited from Entity
#<=>, #id, #label, #lookup_path, #name
Constructor Details
#initialize(name, scenarios, preview) ⇒ ScenarioGroupEntity
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ScenarioGroupEntity.
26 27 28 29 30 31 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 26 def initialize(name, scenarios, preview) @name = Utils.name(name) @scenarios = ScenarioCollection.new(scenarios) @preview = preview @lookup_path = "#{parent.lookup_path}/#{@name}" end |
Instance Attribute Details
#preview ⇒ PreviewEntity (readonly) Also known as: parent
The preview that this scenario belongs to.
20 21 22 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 20 def preview @preview end |
#scenarios ⇒ Array<ScenarioEntity> (readonly)
Returns all scenarios within the group.
13 14 15 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 13 def scenarios @scenarios end |
Instance Method Details
#add_scenario(scenario) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
131 132 133 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 131 def add_scenario(scenario) @scenarios.add(scenario) end |
#display_options ⇒ Hash
Display options hash.
Contains all display options defined via the ‘@display` tag for each scenario in the group, merged with any globally-defined options.
41 42 43 44 45 46 47 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 41 def merged = {} scenarios.to_a.reverse.map do |scenario| merged.merge!(scenario.) end merged end |
#inspect_path ⇒ String Also known as: url_path
The inspector URL path for this scenario group
98 99 100 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 98 def inspect_path lookbook_inspect_path(lookup_path) end |
#preview_path ⇒ String
The standalone preview URL path for this scenario group
105 106 107 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 105 def preview_path lookbook_preview_path(lookup_path) end |
#render_targets ⇒ Array<RenderableEntity> Also known as: components
Collection of render targets (components or partials) from each of the scenarios in the group.
Render targets are guessed where possible (based on the preview class name) but can also be manually specified using the ‘@renders` tag.
63 64 65 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 63 def render_targets @_render_targets ||= RenderTargetCollection.new(scenarios.flat_map(&:render_targets).uniq(&:lookup_path)) end |
#search_terms ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
126 127 128 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 126 def search_terms [parent.search_terms, parent.label, label] end |
#tag(tag_name = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 87 def tag(tag_name = nil) (tag_name).first end |
#tags(tag_name = nil) ⇒ Array<YardTag>
Collection of tags from each of the scenarios in the group. Can be filtered by tag name by providing the name as an argument.
82 83 84 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 82 def (tag_name = nil) scenarios.flat_map { |scenario| scenario.(tag_name) } end |
#type ⇒ Symbol
Entity type identifier. Returns ‘:scenario_group` for scenario groups.
119 120 121 |
# File 'lib/lookbook/entities/scenario_group_entity.rb', line 119 def type :scenario_group end |