Sha256: 8f12ed025d855076b02d949eeeb576dab8b80e7276ac5248c627a0f391d9f2e5

Contents?: true

Size: 1010 Bytes

Versions: 48

Compression:

Stored size: 1010 Bytes

Contents

require_relative 'blob_io'

# An analyzer class that can be hooked to ActiveStorage, in order to enable
# FormatParser to do the blob analysis instead of ActiveStorage builtin-analyzers.
# Invoked if properly integrated in Rails initializer.

module FormatParser
  module ActiveStorage
    class BlobAnalyzer
      # Format parser is able to handle a lot of format so by default it will accept all files
      #
      # @return [Boolean, true] always return true
      def self.accept?(_blob)
        true
      end

      def initialize(blob)
        @blob = blob
      end

      # @return [Hash] file metadatas
      def metadata
        io = BlobIO.new(@blob)
        parsed_file = FormatParser.parse(io)

        if parsed_file
          # We symbolize keys because of existing output hash format of ImageAnalyzer
          parsed_file.as_json.symbolize_keys
        else
          logger.info "Skipping file analysis because FormatParser doesn't support the file"
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
format_parser-2.10.0 lib/active_storage/blob_analyzer.rb
format_parser-2.9.0 lib/active_storage/blob_analyzer.rb
format_parser-2.8.0 lib/active_storage/blob_analyzer.rb
format_parser-2.7.2 lib/active_storage/blob_analyzer.rb
format_parser-2.7.1 lib/active_storage/blob_analyzer.rb
format_parser-2.7.0 lib/active_storage/blob_analyzer.rb
format_parser-2.6.0 lib/active_storage/blob_analyzer.rb
format_parser-2.5.0 lib/active_storage/blob_analyzer.rb
format_parser-2.4.5 lib/active_storage/blob_analyzer.rb
format_parser-2.4.4 lib/active_storage/blob_analyzer.rb
format_parser-2.4.3 lib/active_storage/blob_analyzer.rb
format_parser-2.3.0 lib/active_storage/blob_analyzer.rb
format_parser-2.2.1 lib/active_storage/blob_analyzer.rb
format_parser-2.2.0 lib/active_storage/blob_analyzer.rb
format_parser-2.1.0 lib/active_storage/blob_analyzer.rb
format_parser-2.0.0 lib/active_storage/blob_analyzer.rb
format_parser-2.0.0.pre.4 lib/active_storage/blob_analyzer.rb
format_parser-2.0.0.pre.3 lib/active_storage/blob_analyzer.rb
format_parser-2.0.0.pre.2 lib/active_storage/blob_analyzer.rb
format_parser-2.0.0.pre lib/active_storage/blob_analyzer.rb