Class: Longleaf::MetadataRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/models/metadata_record.rb

Overview

Metadata record for a single file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties: nil, services: nil, deregistered: nil, registered: nil, checksums: nil, file_size: nil, last_modified: nil) ⇒ MetadataRecord

Returns a new instance of MetadataRecord

Parameters:

  • properties (Hash)

    initial data properties for this record

  • services (Hash)

    initial service property tree

  • deregistered (String)

    deregistered timestamp

  • registered (String)

    registered timestamp

  • checksums (Hash)

    hash of checksum values

  • file_size (Integer)

    size of file in bytes

  • last_modified (String)

    iso8601 representation of the last modified date of file



20
21
22
23
24
25
26
27
28
29
# File 'lib/longleaf/models/metadata_record.rb', line 20

def initialize(properties: nil, services: nil, deregistered: nil, registered: nil, checksums: nil,
      file_size: nil, last_modified: nil)
  @properties = properties || Hash.new
  @registered = registered
  @deregistered = deregistered
  @checksums = checksums || Hash.new
  @services = services || Hash.new
  @file_size = file_size
  @last_modified = last_modified
end

Instance Attribute Details

#checksumsObject (readonly)

Returns the value of attribute checksums



9
10
11
# File 'lib/longleaf/models/metadata_record.rb', line 9

def checksums
  @checksums
end

#deregisteredObject

Returns the value of attribute deregistered



8
9
10
# File 'lib/longleaf/models/metadata_record.rb', line 8

def deregistered
  @deregistered
end

#file_sizeObject

Returns the value of attribute file_size



11
12
13
# File 'lib/longleaf/models/metadata_record.rb', line 11

def file_size
  @file_size
end

#last_modifiedObject

Returns the value of attribute last_modified



11
12
13
# File 'lib/longleaf/models/metadata_record.rb', line 11

def last_modified
  @last_modified
end

#propertiesObject (readonly)

Returns the value of attribute properties



10
11
12
# File 'lib/longleaf/models/metadata_record.rb', line 10

def properties
  @properties
end

#registeredObject (readonly)

Returns the value of attribute registered



7
8
9
# File 'lib/longleaf/models/metadata_record.rb', line 7

def registered
  @registered
end

Instance Method Details

#add_service(name, service = ServiceRecord.new) ⇒ ServiceRecord

Adds a service to this record

Parameters:

  • name (String)

    identifier for the service being added

  • service (ServiceRecord) (defaults to: ServiceRecord.new)

    properties for populating the new service

Returns:

Raises:

  • (ArgumentError)


41
42
43
44
45
46
# File 'lib/longleaf/models/metadata_record.rb', line 41

def add_service(name, service = ServiceRecord.new)
  raise ArgumentError.new("Value must be a ServiceRecord object when adding a service") unless service.class == Longleaf::ServiceRecord
  raise IndexError.new("Service with name '#{name}' already exists") if @services.key?(name)

  @services[name] = service
end

#deregistered?Boolean

Returns true if the record is deregistered

Returns:

  • (Boolean)

    true if the record is deregistered



32
33
34
# File 'lib/longleaf/models/metadata_record.rb', line 32

def deregistered?
  !@deregistered.nil?
end

#list_servicesArray<String>

Returns a list of name identifiers for services registered to this record

Returns:

  • (Array<String>)

    a list of name identifiers for services registered to this record



75
76
77
# File 'lib/longleaf/models/metadata_record.rb', line 75

def list_services
  @services.keys
end

#service(name) ⇒ ServiceRecord

Returns the ServiceRecord for the service identified by name, or nil

Parameters:

  • name (String)

    name identifier of the service to retrieve

Returns:

  • (ServiceRecord)

    the ServiceRecord for the service identified by name, or nil



70
71
72
# File 'lib/longleaf/models/metadata_record.rb', line 70

def service(name)
  @services[name]
end

#update_service_as_failed(service_name) ⇒ ServiceRecord

Updates details of service record as if the service had encountered a failure during execution.

Parameters:

  • service_name (String)

    name of the service run

Returns:



62
63
64
65
66
# File 'lib/longleaf/models/metadata_record.rb', line 62

def update_service_as_failed(service_name)
  service_rec = service(service_name) || add_service(service_name)
  service_rec.failure_timestamp = ServiceDateHelper.formatted_timestamp
  service_rec
end

#update_service_as_performed(service_name) ⇒ ServiceRecord

Updates details of service record as if the service had been executed.

Parameters:

  • service_name (String)

    name of the service run

Returns:



51
52
53
54
55
56
# File 'lib/longleaf/models/metadata_record.rb', line 51

def update_service_as_performed(service_name)
  service_rec = service(service_name) || add_service(service_name)
  service_rec.run_needed = false
  service_rec.timestamp = ServiceDateHelper.formatted_timestamp
  service_rec
end