Class: ActiveFedora::FixityService

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Concern
Defined in:
lib/active_fedora/fixity_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ FixityService

Returns a new instance of FixityService.

Parameters:

  • target (String, RDF::URI)

    url for a Fedora resource.

Raises:

  • (ArgumentError)


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

def initialize(target)
  raise ArgumentError, 'You must provide a uri' unless target
  @target = target.to_s
end

Instance Attribute Details

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

Instance Method Details

#checkObject

For backwards compat, check always insists on doing a new request. you might want verified? instead which uses a cached request.

Returns:

  • true or false



20
21
22
23
# File 'lib/active_fedora/fixity_service.rb', line 20

def check
  @response = nil
  verified?
end

#expected_message_digestObject

the currently calculated checksum, as a string URI, like “urn:sha1:09a848b79f86f3a4f3f301b8baafde455d6f8e0e”



40
41
42
# File 'lib/active_fedora/fixity_service.rb', line 40

def expected_message_digest
  fixity_graph.query(predicate: ::RDF::Vocab::PREMIS.hasMessageDigest).first.try(:object).try(:to_s)
end

#expected_sizeObject

integer, as reported by fedora. bytes maybe?



45
46
47
# File 'lib/active_fedora/fixity_service.rb', line 45

def expected_size
  fixity_graph.query(predicate: ::RDF::Vocab::PREMIS.hasSize).first.try(:object).try(:to_s).try(:to_i)
end

#responseObject



13
14
15
# File 'lib/active_fedora/fixity_service.rb', line 13

def response
  @response ||= fixity_response_from_fedora
end

#response_graphObject

Fedora response as an ::RDF::Graph object. Public API, so consumers can do with it what they will, especially if future fedora versions add more things to it.



52
53
54
# File 'lib/active_fedora/fixity_service.rb', line 52

def response_graph
  fixity_graph
end

#statusObject

An array of 1 or more literals reported by Fedora. See ‘success’ for which one indicates fixity check is good.



33
34
35
36
# File 'lib/active_fedora/fixity_service.rb', line 33

def status
  fixity_graph.query(predicate: premis_status_predicate).map(&:object) +
    fixity_graph.query(predicate: fedora_status_predicate).map(&:object)
end

#verified?Boolean

Executes a fixity check on Fedora

Returns:

  • (Boolean)

    true or false



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

def verified?
  status.include?(success)
end