Class: Wallaby::ActiveRecord::ModelDecorator::TitleFieldFinder
- Inherits:
-
Object
- Object
- Wallaby::ActiveRecord::ModelDecorator::TitleFieldFinder
- Defined in:
- lib/adapters/wallaby/active_record/model_decorator/title_field_finder.rb
Overview
Try to find the field that can be used as title
Constant Summary collapse
- TITLE_FIELD_TYPES =
%w[string].freeze
Instance Method Summary collapse
-
#find ⇒ String
Field name that can be used as title.
-
#initialize(model_class, fields) ⇒ TitleFieldFinder
constructor
A new instance of TitleFieldFinder.
Constructor Details
#initialize(model_class, fields) ⇒ TitleFieldFinder
Returns a new instance of TitleFieldFinder.
12 13 14 15 |
# File 'lib/adapters/wallaby/active_record/model_decorator/title_field_finder.rb', line 12 def initialize(model_class, fields) @model_class = model_class @fields = fields end |
Instance Method Details
#find ⇒ String
Returns field name that can be used as title.
18 19 20 21 22 23 24 25 |
# File 'lib/adapters/wallaby/active_record/model_decorator/title_field_finder.rb', line 18 def find FieldUtils.first_field_by( { name: /title|name|label|string/, type: 'string' }, @fields ) || @model_class.primary_key end |