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, physical_path: nil) ⇒ MetadataRecord

Returns a new instance of MetadataRecord.

Parameters:

  • properties (Hash) (defaults to: nil)

    initial data properties for this record

  • services (Hash) (defaults to: nil)

    initial service property tree

  • deregistered (String) (defaults to: nil)

    deregistered timestamp

  • registered (String) (defaults to: nil)

    registered timestamp

  • checksums (Hash) (defaults to: nil)

    hash of checksum values

  • file_size (Integer) (defaults to: nil)

    size of file in bytes

  • last_modified (String) (defaults to: nil)

    iso8601 representation of the last modified date of file

  • physical_path (String) (defaults to: nil)

    physical path where the file is located



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/longleaf/models/metadata_record.rb', line 23

def initialize(properties: nil, services: nil, deregistered: nil, registered: nil, checksums: nil,
      file_size: nil, last_modified: nil, physical_path: nil)
  @properties = properties || Hash.new
  @registered = registered
  @deregistered = deregistered
  @checksums = CaseInsensitiveHash.new
  @checksums.merge!(checksums) unless checksums.nil?
  @services = services || Hash.new
  @file_size = file_size
  @last_modified = last_modified
  @physical_path = physical_path
end

Instance Attribute Details

#checksumsObject (readonly)

Returns the value of attribute checksums.



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

def checksums
  @checksums
end

#deregisteredObject

Returns the value of attribute deregistered.



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

def deregistered
  @deregistered
end

#file_sizeObject

Returns the value of attribute file_size.



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

def file_size
  @file_size
end

#last_modifiedObject

Returns the value of attribute last_modified.



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

def last_modified
  @last_modified
end

#physical_pathObject

Returns the value of attribute physical_path.



13
14
15
# File 'lib/longleaf/models/metadata_record.rb', line 13

def physical_path
  @physical_path
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

#registeredObject (readonly)

Returns the value of attribute registered.



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

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)


46
47
48
49
50
51
# File 'lib/longleaf/models/metadata_record.rb', line 46

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



37
38
39
# File 'lib/longleaf/models/metadata_record.rb', line 37

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



80
81
82
# File 'lib/longleaf/models/metadata_record.rb', line 80

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



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

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:



67
68
69
70
71
# File 'lib/longleaf/models/metadata_record.rb', line 67

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:



56
57
58
59
60
61
# File 'lib/longleaf/models/metadata_record.rb', line 56

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