Sha256: b92c4ebfb05b888863c0328bdd0fcf2f1efbee4a65a2aa029bee83765b8d6b5d

Contents?: true

Size: 925 Bytes

Versions: 3

Compression:

Stored size: 925 Bytes

Contents

module Blueimp
  module FileUpload
    module File
      extend ActiveSupport::Concern
      BLUEIMP_PARAMS = [:name, :size, :url, :thumbnail_url, :delete_url, :delete_type]

      def as_json(options = {})
        {}.tap do |json|
          BLUEIMP_PARAMS.each do |param|
            raise "Blueimp::FileUpload::File requires a method '#{param}'" if !respond_to?(param)
            json[param] = send param
          end
        end
      end

      module ClassMethods
        def from_params(params)
          { :files => from_param(params[:files]) }
        end

        def from_param(param)
          param = [param] unless param.kind_of?(Array)

          [].tap do |list|
            param.each do |p|
              list << new.tap do |file|
                file.name = p.original_filename
                file.contents = p.read
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blueimp-file-upload-rails-8.6.1.1 app/models/blueimp/file_upload/file.rb
blueimp-file-upload-rails-8.6.1 app/models/blueimp/file_upload/file.rb
blueimp-file-upload-rails-8.5.0 app/models/blueimp/file_upload/file.rb