Class: OpsBuild::BoxIndexer

Inherits:
Object
  • Object
show all
Defined in:
lib/ops_build/box_indexer.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir:, out:, name:, desc:, root_url:, checksum_type: :sha1) ⇒ BoxIndexer

Returns a new instance of BoxIndexer.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/ops_build/box_indexer.rb', line 3

def initialize(dir:, out:, name:, desc:, root_url:, checksum_type: :sha1)
  @dir           = File.expand_path(dir)
  @out           = out
  @name          = name
  @desc          = desc
  @root_url      = root_url
  @checksum_type = checksum_type

  check_dir!
  check_checksum_type!
end

Instance Method Details

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ops_build/box_indexer.rb', line 15

def index
  OpsBuild.logger.debug("Indexing directory '#{@dir}'")
  out = {
      name:        @name,
      description: @desc,
      versions:    []
  }

  Dir.glob("#{@dir}/*.box").each do |path|
    filename = File.basename(path)
    m = /^#{@name}[\_\-](?<version>[0-9]+((\.[0-9A-Z]+){1,}([\-\.][0-9]+))?)\.box$/.match(filename)
    next if m.nil?

    OpsBuild.logger.debug("Found box '#{filename}'")

    out[:versions] << box_info(File.expand_path(path), m[:version])
  end

  out
end

#index!Object



36
37
38
# File 'lib/ops_build/box_indexer.rb', line 36

def index!
  write(index)
end