Sha256: 61ee91d0c851ac73916cf36984d0397a12652187dcda21bd2330dd9e776df210

Contents?: true

Size: 928 Bytes

Versions: 9

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module RailsExecution
  module Files
    class Uploader

      def initialize(task, inputs, owner: nil)
        @task = task
        @files = files_filter(inputs).compact
        @owner = owner
      end

      def call
        raise ::NotImplementedError, 'File uploader'
      end

      private

      attr_reader :task
      attr_reader :files
      attr_reader :owner

      def files_filter(inputs)
        inputs.map do |_multiple, attachment|
          next if attachment['name'].blank?
          next if attachment['file'].blank?
          next unless attachment['file'].content_type.in?(acceptable_file_types)

          OpenStruct.new({
            name: attachment['name'],
            file: attachment['file'],
          })
        end
      end

      def acceptable_file_types
        ::RailsExecution.configuration.acceptable_file_types.values.flatten
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_execution-0.1.12 lib/rails_execution/files/uploader.rb
rails_execution-0.1.11 lib/rails_execution/files/uploader.rb
rails_execution-0.1.10 lib/rails_execution/files/uploader.rb
rails_execution-0.1.9 lib/rails_execution/files/uploader.rb
rails_execution-0.1.8 lib/rails_execution/files/uploader.rb
rails_execution-0.1.7 lib/rails_execution/files/uploader.rb
rails_execution-0.1.5 lib/rails_execution/files/uploader.rb
rails_execution-0.1.4 lib/rails_execution/files/uploader.rb
rails_execution-0.1.2 lib/rails_execution/files/uploader.rb