Class: Maglev::Editor::SettingsGroupComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/maglev/editor/settings_group_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values:, definitions:, scope:, paths: {}) ⇒ SettingsGroupComponent

Returns a new instance of SettingsGroupComponent.



8
9
10
11
12
13
# File 'app/components/maglev/editor/settings_group_component.rb', line 8

def initialize(values:, definitions:, scope:, paths: {})
  @values = values
  @definitions = definitions
  @paths = paths
  @scope = scope
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



6
7
8
# File 'app/components/maglev/editor/settings_group_component.rb', line 6

def definitions
  @definitions
end

#pathsObject (readonly)

Returns the value of attribute paths.



6
7
8
# File 'app/components/maglev/editor/settings_group_component.rb', line 6

def paths
  @paths
end

#scopeObject (readonly)

Returns the value of attribute scope.



6
7
8
# File 'app/components/maglev/editor/settings_group_component.rb', line 6

def scope
  @scope
end

#valuesObject (readonly)

Returns the value of attribute values.



6
7
8
# File 'app/components/maglev/editor/settings_group_component.rb', line 6

def values
  @values
end

Instance Method Details

#setting_instance_for(definition) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'app/components/maglev/editor/settings_group_component.rb', line 15

def setting_instance_for(definition)
  component_klass = Maglev::Editor::SettingRegistry.instance.fetch(definition)
  component_klass.new(
    definition: definition,
    value: value_of(definition.id),
    paths: paths,
    scope: scope
  )
end

#value_of(definition_id) ⇒ Object



25
26
27
# File 'app/components/maglev/editor/settings_group_component.rb', line 25

def value_of(definition_id)
  values.find { |value| value.id == definition_id }&.value
end