Class: Maglev::Editor::SettingRegistry::Instance
- Inherits:
-
Object
- Object
- Maglev::Editor::SettingRegistry::Instance
- Defined in:
- app/components/maglev/editor/setting_registry.rb
Overview
rubocop:enable Metrics/MethodLength
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Instance Method Summary collapse
- #fetch(definition) ⇒ Object
-
#initialize(components: {}) ⇒ Instance
constructor
A new instance of Instance.
- #register(type, component_klass_or_proc) ⇒ Object
- #text_field_klass(definition) ⇒ Object
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
#components ⇒ Object (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.[:html] Maglev::Editor::Settings::Text::RichtextComponent elsif definition.[:nb_rows].to_i > 1 Maglev::Editor::Settings::Text::TextareaComponent else Maglev::Editor::Settings::Text::TextComponent end end |