Sha256: 2601b9d08aacff61340a4083190379e5f714c1eba7605f8450653c7773b9cd79
Contents?: true
Size: 590 Bytes
Versions: 2
Compression:
Stored size: 590 Bytes
Contents
class Wallaby::ActiveRecord::ModelDecorator::TitleFieldFinder def initialize(model_class, fields) @model_class = model_class @fields = fields end def find possible_title_fields = @fields.select do |field_name, metadata| %w( string ).include? metadata[:type] end target_field = possible_title_fields.values.find do |metadata| %w( name title string text ).any?{ |v| metadata[:name].index v } end target_field ||= possible_title_fields.values.first target_field ||= { name: @model_class.primary_key } target_field[:name] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wallaby-4.1.6 | lib/adaptors/wallaby/active_record/model_decorator/title_field_finder.rb |
wallaby-5.0.1 | lib/adaptors/wallaby/active_record/model_decorator/title_field_finder.rb |