Class: Hyrax::Actors::FileActor

Inherits:
Object
  • Object
show all
Defined in:
app/actors/hyrax/actors/file_actor.rb

Overview

actions for a file identified by file_set and relation (maps to use predicate)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set, relation, user) ⇒ FileActor

Returns a new instance of FileActor.

Parameters:

  • file_set (FileSet)

    the parent FileSet

  • relation (String)

    the type/use for the file.

  • user (User)

    the user to record as the Agent acting upon the file



10
11
12
13
14
# File 'app/actors/hyrax/actors/file_actor.rb', line 10

def initialize(file_set, relation, user)
  @file_set = file_set
  @relation = relation
  @user = user
end

Instance Attribute Details

#file_setObject (readonly)

Returns the value of attribute file_set.



5
6
7
# File 'app/actors/hyrax/actors/file_actor.rb', line 5

def file_set
  @file_set
end

#relationObject (readonly)

Returns the value of attribute relation.



5
6
7
# File 'app/actors/hyrax/actors/file_actor.rb', line 5

def relation
  @relation
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'app/actors/hyrax/actors/file_actor.rb', line 5

def user
  @user
end

Instance Method Details

#ingest_file(file, asynchronous) ⇒ Object

Puts the uploaded content into a staging directory. Then kicks off a job to ingest the file into the repository, then characterize and create derivatives with this on disk variant. TODO: create a job to monitor this directory and prune old files that have made it to the repo

Parameters:

  • file (File, ActionDigest::HTTP::UploadedFile, Tempfile)

    the file to save in the repository

  • asynchronous (Boolean)

    set to true if you want to launch a new background job.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/actors/hyrax/actors/file_actor.rb', line 23

def ingest_file(file, asynchronous)
  method = if asynchronous
             :perform_later
           else
             :perform_now
           end

  IngestFileJob.send(method,
                     file_set,
                     working_file(file),
                     user,
                     ingest_options(file))
  true
end

#revert_to(revision_id) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/actors/hyrax/actors/file_actor.rb', line 38

def revert_to(revision_id)
  repository_file = file_set.send(relation.to_sym)
  repository_file.restore_version(revision_id)

  return false unless file_set.save

  Hyrax::VersioningService.create(repository_file, user)

  # Characterize the original file from the repository
  CharacterizeJob.perform_later(file_set, repository_file.id)
  true
end