Class: ViewComponent::Storybook::Collections::ParametersCollection

Inherits:
Object
  • Object
show all
Includes:
ValidForStoryConcern
Defined in:
lib/view_component/storybook/collections/parameters_collection.rb

Instance Method Summary collapse

Methods included from ValidForStoryConcern

#valid_for_story?

Constructor Details

#initializeParametersCollection

Returns a new instance of ParametersCollection.



9
10
11
12
# File 'lib/view_component/storybook/collections/parameters_collection.rb', line 9

def initialize
  @all_paramsters = {}
  @parameters = []
end

Instance Method Details

#add(params, only: nil, except: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/view_component/storybook/collections/parameters_collection.rb', line 14

def add(params, only: nil, except: nil)
  if only.nil? && except.nil?
    all_paramsters.merge!(params)
  else
    parameters << { params: params, only: only, except: except }
  end
end

#for_allObject

Parameters set for all stories



23
24
25
# File 'lib/view_component/storybook/collections/parameters_collection.rb', line 23

def for_all
  all_paramsters
end

#for_story(story_name) ⇒ Object

Parameters set for the story method



28
29
30
31
32
# File 'lib/view_component/storybook/collections/parameters_collection.rb', line 28

def for_story(story_name)
  parameters.each_with_object({}) do |opts, accum|
    accum.merge!(opts[:params]) if valid_for_story?(story_name, **opts.slice(:only, :except))
  end
end