Class: ActiveStorage::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_storage/analyzer.rb

Overview

This is an abstract base class for analyzers, which extract metadata from blobs. See ActiveStorage::Analyzer::VideoAnalyzer for an example of a concrete subclass.

Defined Under Namespace

Classes: AudioAnalyzer, ImageAnalyzer, NullAnalyzer, VideoAnalyzer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob) ⇒ Analyzer

Returns a new instance of Analyzer.



21
22
23
# File 'lib/active_storage/analyzer.rb', line 21

def initialize(blob)
  @blob = blob
end

Instance Attribute Details

#blobObject (readonly)

Returns the value of attribute blob.



7
8
9
# File 'lib/active_storage/analyzer.rb', line 7

def blob
  @blob
end

Class Method Details

.accept?(blob) ⇒ Boolean

Implement this method in a concrete subclass. Have it return true when given a blob from which the analyzer can extract metadata.

Returns:

  • (Boolean)


11
12
13
# File 'lib/active_storage/analyzer.rb', line 11

def self.accept?(blob)
  false
end

.analyze_later?Boolean

Implement this method in concrete subclasses. It will determine if blob analysis should be done in a job or performed inline. By default, analysis is enqueued in a job.

Returns:

  • (Boolean)


17
18
19
# File 'lib/active_storage/analyzer.rb', line 17

def self.analyze_later?
  true
end

Instance Method Details

#metadataObject

Override this method in a concrete subclass. Have it return a Hash of metadata.

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/active_storage/analyzer.rb', line 26

def 
  raise NotImplementedError
end