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.



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

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

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



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

def item
  @item
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#create_work_from_itemObject



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

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



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

def destroy_work(work)
  work.destroy
end

#update_work_from_item(work) ⇒ Object



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

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