Class: Maglev::Editor::SettingRegistry::Instance

Inherits:
Object
  • Object
show all
Defined in:
app/components/maglev/editor/setting_registry.rb

Overview

rubocop:enable Metrics/MethodLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(components: {}) ⇒ Instance

Returns a new instance of Instance.



30
31
32
# File 'app/components/maglev/editor/setting_registry.rb', line 30

def initialize(components: {})
  @components = components
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



28
29
30
# File 'app/components/maglev/editor/setting_registry.rb', line 28

def components
  @components
end

Instance Method Details

#fetch(definition) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/components/maglev/editor/setting_registry.rb', line 38

def fetch(definition)
  klass_or_proc = components.fetch(definition.type.to_sym, nil)
  klass = klass_or_proc.is_a?(Proc) ? klass_or_proc.call(definition) : klass_or_proc

  return Maglev::Editor::Settings::BaseComponent if klass.nil?

  klass
end

#register(type, component_klass_or_proc) ⇒ Object



34
35
36
# File 'app/components/maglev/editor/setting_registry.rb', line 34

def register(type, component_klass_or_proc)
  components[type.to_sym] = component_klass_or_proc
end

#text_field_klass(definition) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'app/components/maglev/editor/setting_registry.rb', line 47

def text_field_klass(definition)
  if definition.options[:html]
    Maglev::Editor::Settings::Text::RichtextComponent
  elsif definition.options[:nb_rows].to_i > 1
    Maglev::Editor::Settings::Text::TextareaComponent
  else
    Maglev::Editor::Settings::Text::TextComponent
  end
end