Class: Kiba::Extend::Registry::FileRegistry

Inherits:
Object
  • Object
show all
Includes:
Dry::Container::Mixin
Defined in:
lib/kiba/extend/registry/file_registry.rb

Overview

Transforms a file_registry hash into an object that can return source, lookup, or destination config for that file, for passing to jobs

An example of a file registry setup in a project can be found at: https://github.com/lyrasis/fwm-cspace-migration/blob/main/lib/fwm/registry_data.rb

Since:

  • 2.2.0

Defined Under Namespace

Classes: KeyNotRegisteredError

Instance Method Summary collapse

Instance Method Details

#as_destination(filekey, for_job) ⇒ Kiba::Extend::Registry::RegisteredDestination

Parameters:

  • filekey (String, Symbol)

    file registry key for file to be used as destination

Returns:

Since:

  • 2.2.0



45
46
47
48
49
50
51
52
53
# File 'lib/kiba/extend/registry/file_registry.rb', line 45

def as_destination(filekey, for_job)
  RegisteredDestination.new(
    key: filekey,
    data: lookup(filekey),
    for_job: for_job
  )
rescue KeyNotRegisteredError => err
  raise KeyNotRegisteredError.new(err.key, :destination)
end

#as_lookup(filekey, for_job) ⇒ Kiba::Extend::Registry::RegisteredLookup

Parameters:

  • filekey (String, Symbol)

    file registry key for file to be used as a lookup source

Returns:

Since:

  • 2.2.0



58
59
60
61
62
63
64
65
66
# File 'lib/kiba/extend/registry/file_registry.rb', line 58

def as_lookup(filekey, for_job)
  RegisteredLookup.new(
    key: filekey,
    data: lookup(filekey),
    for_job: for_job
  )
rescue KeyNotRegisteredError => err
  raise KeyNotRegisteredError.new(err.key, :lookup)
end

#as_source(filekey, for_job) ⇒ Kiba::Extend::Registry::RegisteredSource

Parameters:

  • filekey (String, Symbol)

    file registry key for file to be used as a source

Returns:

Since:

  • 2.2.0



71
72
73
74
75
76
77
78
79
# File 'lib/kiba/extend/registry/file_registry.rb', line 71

def as_source(filekey, for_job)
  RegisteredSource.new(
    key: filekey,
    data: lookup(filekey),
    for_job: for_job
  )
rescue KeyNotRegisteredError => err
  raise KeyNotRegisteredError.new(err.key, :source)
end

#entriesObject

Returns:

Since:

  • 2.2.0



82
83
84
# File 'lib/kiba/extend/registry/file_registry.rb', line 82

def entries
  @entries ||= populate_entries
end

#finalizeObject

Convenience method combining the steps of transforming initial registry entry hashes into FileRegistryEntry objects, and then making the registry immutable for the rest of the application’s run. :freeze is from dry-container.

Since:

  • 2.2.0



91
92
93
94
# File 'lib/kiba/extend/registry/file_registry.rb', line 91

def finalize
  transform
  freeze
end

#transformObject

Transforms registered file hashes into Kiba::Extend::Registry::FileRegistryEntry objects

Since:

  • 2.2.0



98
99
100
101
102
103
# File 'lib/kiba/extend/registry/file_registry.rb', line 98

def transform
  each { |key, val| decorate(key) { FileRegistryEntry.new(val) } }
  @entries = populate_entries
  each { |key, val| val.set_key(key) }
  verify_paths
end

#valid?Boolean

Returns:

  • (Boolean)

Since:

  • 2.2.0



105
106
107
# File 'lib/kiba/extend/registry/file_registry.rb', line 105

def valid?
  validator.valid?
end

#warnings?Boolean

Returns:

  • (Boolean)

Since:

  • 2.2.0



109
110
111
# File 'lib/kiba/extend/registry/file_registry.rb', line 109

def warnings?
  validator.warnings?
end