Class: Hyrax::Arkivo::Actor

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/arkivo/actor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, item) ⇒ Actor

Returns a new instance of Actor.



15
16
17
18
# File 'lib/hyrax/arkivo/actor.rb', line 15

def initialize(user, item)
  @user = user
  @item = item
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



13
14
15
# File 'lib/hyrax/arkivo/actor.rb', line 13

def item
  @item
end

#userObject (readonly)

Returns the value of attribute user.



13
14
15
# File 'lib/hyrax/arkivo/actor.rb', line 13

def user
  @user
end

Instance Method Details

#create_work_from_itemObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hyrax/arkivo/actor.rb', line 20

def create_work_from_item
  work = Hyrax.primary_work_type.new
  work_actor = Hyrax::CurationConcern.actor
  create_attrs = attributes.merge(arkivo_checksum: item['file']['md5'])
  env = Actors::Environment.new(work, current_ability, create_attrs)
  raise "Unable to create work. #{work.errors.messages}" unless work_actor.create(env)

  file_set = ::FileSet.new

  file_actor = ::Hyrax::Actors::FileSetActor.new(file_set, user)
  file_actor.
  file_set.label = item['file']['filename']
  file_actor.create_content(file) # item['file']['contentType']
  file_actor.attach_to_work(work)

  work
end

#destroy_work(work) ⇒ Object



50
51
52
# File 'lib/hyrax/arkivo/actor.rb', line 50

def destroy_work(work)
  work.destroy
end

#update_work_from_item(work) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hyrax/arkivo/actor.rb', line 38

def update_work_from_item(work)
  work_actor = Hyrax::CurationConcern.actor
  work_attributes = default_attributes.merge(attributes).merge(arkivo_checksum: item['file']['md5'])
  env = Actors::Environment.new(work, current_ability, work_attributes)
  work_actor.update(env)

  file_set = work.file_sets.first
  file_actor = ::Hyrax::Actors::FileSetActor.new(file_set, user)
  file_actor.update_content(file)
  work
end