Class: Hyrax::CustomQueries::Navigators::FindFiles

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/custom_queries/navigators/find_files.rb

Overview

Examples:

Hyrax.custom_queries.find_files(file_set: file_set_resource)
Hyrax.custom_queries.find_original_file(file_set: file_set_resource)
Hyrax.custom_queries.find_extracted_text(file_set: file_set_resource)
Hyrax.custom_queries.find_thumbnail(file_set: file_set_resource)

See Also:

Since:

  • 3.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindFiles

Returns a new instance of FindFiles.

Since:

  • 3.0.0



22
23
24
# File 'app/services/hyrax/custom_queries/navigators/find_files.rb', line 22

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Since:

  • 3.0.0



26
27
28
# File 'app/services/hyrax/custom_queries/navigators/find_files.rb', line 26

def query_service
  @query_service
end

Class Method Details

.queriesObject

Since:

  • 3.0.0



15
16
17
18
19
20
# File 'app/services/hyrax/custom_queries/navigators/find_files.rb', line 15

def self.queries
  [:find_files,
   :find_original_file,
   :find_extracted_text,
   :find_thumbnail]
end

Instance Method Details

#find_extracted_text(file_set:) ⇒ Hyrax::FileMetadata

Find extracted text id of a given file set resource, and map to file metadata resource

Parameters:

Returns:

Since:

  • 3.0.0



55
56
57
58
59
60
# File 'app/services/hyrax/custom_queries/navigators/find_files.rb', line 55

def find_extracted_text(file_set:)
  find_exactly_one_file_by_use(
    file_set: file_set,
    use: Hyrax::FileMetadata::Use::EXTRACTED_TEXT
  )
end

#find_files(file_set:) ⇒ Array<Hyrax::FileMetadata>

Find file ids of a given file set resource, and map to file metadata resources

Parameters:

Returns:

Since:

  • 3.0.0



32
33
34
35
36
37
38
39
40
# File 'app/services/hyrax/custom_queries/navigators/find_files.rb', line 32

def find_files(file_set:)
  if file_set.respond_to?(:file_ids)
    return [] if file_set.file_ids.blank?
    query_service.custom_queries.(ids: file_set.file_ids)
  else
    raise ::Valkyrie::Persistence::ObjectNotFoundError,
          "#{file_set.internal_resource} is not a `Hydra::FileSet` implementer"
  end
end

#find_original_file(file_set:) ⇒ Hyrax::FileMetadata

Find original file id of a given file set resource, and map to file metadata resource

Parameters:

Returns:

Since:

  • 3.0.0



45
46
47
48
49
50
# File 'app/services/hyrax/custom_queries/navigators/find_files.rb', line 45

def find_original_file(file_set:)
  find_exactly_one_file_by_use(
    file_set: file_set,
    use: Hyrax::FileMetadata::Use::ORIGINAL_FILE
  )
end

#find_thumbnail(file_set:) ⇒ Hyrax::FileMetadata

Find thumbnail id of a given file set resource, and map to file metadata resource

Parameters:

Returns:

Since:

  • 3.0.0



65
66
67
68
69
70
# File 'app/services/hyrax/custom_queries/navigators/find_files.rb', line 65

def find_thumbnail(file_set:)
  find_exactly_one_file_by_use(
    file_set: file_set,
    use: Hyrax::FileMetadata::Use::THUMBNAIL_IMAGE
  )
end