Class: RubyUiScaffold::FieldTypeMapper
- Inherits:
-
Object
- Object
- RubyUiScaffold::FieldTypeMapper
- Defined in:
- lib/ruby_ui_scaffold/field_type_mapper.rb
Overview
Maps a Rails::Generators::GeneratedAttribute to a ruby_ui input component, emitted as a Ruby code snippet for interpolation into a Phlex view template.
Multi-line snippets are returned with newline separators and NO leading indentation; the caller is responsible for indenting subsequent lines to match its context. The generator wraps this via ‘ruby_ui_input_for(attribute, indent:)`.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attribute, model_var) ⇒ FieldTypeMapper
constructor
A new instance of FieldTypeMapper.
- #render ⇒ Object
Constructor Details
#initialize(attribute, model_var) ⇒ FieldTypeMapper
Returns a new instance of FieldTypeMapper.
21 22 23 24 |
# File 'lib/ruby_ui_scaffold/field_type_mapper.rb', line 21 def initialize(attribute, model_var) @attr = attribute @model_var = model_var.to_s end |
Class Method Details
.render(attribute, model_var:) ⇒ Object
17 18 19 |
# File 'lib/ruby_ui_scaffold/field_type_mapper.rb', line 17 def self.render(attribute, model_var:) new(attribute, model_var).render end |
Instance Method Details
#render ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ruby_ui_scaffold/field_type_mapper.rb', line 26 def render return password_input if @attr.respond_to?(:password_digest?) && @attr.password_digest? return file_input if @attr.respond_to?(:attachment?) && (@attr. || @attr.) return reference_input if @attr.respond_to?(:reference?) && @attr.reference? type_input end |