Class: ActiveFedora::FixtureLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/fixture_loader.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FixtureLoader) initialize(path)



5
6
7
# File 'lib/active_fedora/fixture_loader.rb', line 5

def initialize(path)
  self.path = path
end

Instance Attribute Details

- (Object) path

Returns the value of attribute path



3
4
5
# File 'lib/active_fedora/fixture_loader.rb', line 3

def path
  @path
end

Class Method Details

+ (Object) delete(pid)



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_fedora/fixture_loader.rb', line 13

def self.delete(pid)
  begin
    ActiveFedora::Base.find(pid, cast: true).delete
    1
  rescue ActiveFedora::ObjectNotFoundError
    ActiveFedora::Base.logger.debug "The object #{pid} has already been deleted (or was never created)." if ActiveFedora::Base.logger
    0
  rescue Errno::ECONNREFUSED => e
    ActiveFedora::Base.logger.debug "Can't connect to Fedora! Are you sure jetty is running?" if ActiveFedora::Base.logger
   0
  end
end

+ (Object) import_to_fedora(filename, pid = '0')



41
42
43
44
45
46
# File 'lib/active_fedora/fixture_loader.rb', line 41

def self.import_to_fedora(filename, pid='0')
  file = File.new(filename, "r")
  result = ActiveFedora::Base.connection_for_pid(pid).ingest(:file=>file.read)
  raise "Failed to ingest the fixture." unless result
  result.body
end

+ (Object) index(pid)



37
38
39
# File 'lib/active_fedora/fixture_loader.rb', line 37

def self.index(pid)
  ActiveFedora::Base.find(pid).update_index
end

Instance Method Details

- (Object) filename_for_pid(pid)



9
10
11
# File 'lib/active_fedora/fixture_loader.rb', line 9

def filename_for_pid(pid)
  File.join(path, "#{pid.gsub(":","_")}.foxml.xml")
end

- (Object) import_and_index(pid)



31
32
33
34
35
# File 'lib/active_fedora/fixture_loader.rb', line 31

def import_and_index(pid)
  body = self.class.import_to_fedora(filename_for_pid(pid), pid)
  self.class.index(pid)
  body
end

- (Object) reload(pid)



26
27
28
29
# File 'lib/active_fedora/fixture_loader.rb', line 26

def reload(pid)
  self.class.delete(pid)
  import_and_index(pid)
end