Sha256: 26c4d0b7d5d4e2c2d56361cae968947d5cdabb3edfa8f29a0a0326bb276a9631

Contents?: true

Size: 388 Bytes

Versions: 2

Compression:

Stored size: 388 Bytes

Contents

# frozen_string_literal: true

module ModelAuditor
  module AttributeReaders
    class ArrayField < Associated
      def value
        return unless method_name

        values = model.send(method_name).map { |i| i.try(:title) }
        values.join(', ') if values.try(:all?)
      end

      private

      def method_name
        attr_name(/[s]?_ids$/, 's')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
model_auditor-0.0.2 lib/model_auditor/attribute_readers/array_field.rb
model_auditor-0.0.1 lib/model_auditor/attribute_readers/array_field.rb