Class: Lexicon::Common::Package::V1::PackageBuilder

Inherits:
Package show all
Defined in:
lib/lexicon/common/package/v1/package_builder.rb

Constant Summary

Constants inherited from Package

Package::CHECKSUM_FILE_NAME, Package::SPEC_FILE_NAME

Instance Attribute Summary

Attributes inherited from Package

#file_sets

Attributes inherited from Package

#checksum_file, #dir, #schema_version, #spec_file, #version

Instance Method Summary collapse

Methods inherited from Package

#data_dir, #data_path, #files, #relative_data_path, #relative_structure_path, #valid?

Methods inherited from Package

#files, #valid?

Constructor Details

#initialize(version:, dir:) ⇒ PackageBuilder

Returns a new instance of PackageBuilder.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lexicon/common/package/v1/package_builder.rb', line 8

def initialize(version:, dir:)
  super(
    file_sets: [],
    version: version,
    dir: dir,
    checksum_file: dir.join(CHECKSUM_FILE_NAME),
    spec_file: dir.join(SPEC_FILE_NAME)
  )

  FileUtils.mkdir_p(data_dir)
end

Instance Method Details

#add_file_set(id, name:, structure:, tables:, data: nil, data_ext: '.sql') ⇒ Object

Parameters:

  • id (String)
  • name (String)
  • structure (Pathname)

    Takes ownership of the file (moves it to the correct folder)

  • tables (Array<String>)
  • data (Pathname) (defaults to: nil)

    Takes ownership of the file (moves it to the correct folder)

  • data_ext (String) (defaults to: '.sql')


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lexicon/common/package/v1/package_builder.rb', line 28

def add_file_set(id, name:, structure:, tables:, data: nil, data_ext: '.sql')
  # @type [Pathname] structure_file_path
  structure_file_path = data_dir.join(structure_file_name(id))
  FileUtils.mv(structure.to_s, structure_file_path.to_s)

  # @type [Pathname] data_file_path
  data_name = if data.nil?
                nil
              else
                dname = data_file_name(id, data_ext)
                path = data_dir.join(dname)
                FileUtils.mv(data, path)

                dname
              end

  file_sets << SourceFileSet.new(
    id: id,
    name: name,
    structure: structure_file_name(id),
    data: data.nil? ? nil : data_name,
    tables: tables
  )
end

#as_packageObject



53
54
55
# File 'lib/lexicon/common/package/v1/package_builder.rb', line 53

def as_package
  Package.new(version: version, dir: dir, file_sets: file_sets, checksum_file: checksum_file, spec_file: spec_file)
end