Sha256: d4624822af3ea414f6125583ee2591e85d2f043b932523502fab1cc6d988a2fd

Contents?: true

Size: 797 Bytes

Versions: 15

Compression:

Stored size: 797 Bytes

Contents

module Compony
  module ModelFields
    # @api description
    # Model field type representing an ActiveStorage attachment.
    class Attachment < Base
      def value_for(data, controller: nil, **_)
        return transform_and_join(data.send(@name), controller:) do |el|
          fail('Must pass controller to generate the link to the attachment.') unless controller
          return nil unless el.attached?
          return controller.helpers.link_to(I18n.t('compony.model_fields.attachment.download'), controller.helpers.rails_blob_path(el))
        end
      end

      def simpleform_input(form, _component, name: nil, accept: nil, **input_opts)
        input_opts.merge!(input_html: { accept: }) if accept
        return form.input(name || @name, **input_opts)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
compony-0.4.0 lib/compony/model_fields/attachment.rb
compony-0.3.3 lib/compony/model_fields/attachment.rb
compony-0.3.2 lib/compony/model_fields/attachment.rb
compony-0.3.1 lib/compony/model_fields/attachment.rb
compony-0.3.0 lib/compony/model_fields/attachment.rb
compony-0.2.3 lib/compony/model_fields/attachment.rb
compony-0.2.2 lib/compony/model_fields/attachment.rb
compony-0.2.1 lib/compony/model_fields/attachment.rb
compony-0.2.0 lib/compony/model_fields/attachment.rb
compony-0.1.1 lib/compony/model_fields/attachment.rb
compony-0.1.0 lib/compony/model_fields/attachment.rb
compony-0.0.9 lib/compony/model_fields/attachment.rb
compony-0.0.8 lib/compony/model_fields/attachment.rb
compony-0.0.7 lib/compony/model_fields/attachment.rb
compony-0.0.6 lib/compony/model_fields/attachment.rb