Class: ReaperMan::Generator

Inherits:
Object
  • Object
show all
Includes:
Utils::Checksum
Defined in:
lib/reaper-man/generator.rb,
lib/reaper-man/generator/apt.rb,
lib/reaper-man/generator/yum.rb,
lib/reaper-man/generator/rubygems.rb

Overview

Repository generator

Defined Under Namespace

Modules: Apt, Rubygems, Yum

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Checksum

#checksum

Constructor Details

#initialize(args = {}) ⇒ Generator

Create new instance

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :package_system (String)

    apt/gem/etc…

  • :package_config (Hash)
  • :signer (Signer)


31
32
33
34
35
36
37
# File 'lib/reaper-man/generator.rb', line 31

def initialize(args = {})
  @package_system = args[:package_system]
  @package_config = args.fetch(:package_config, Smash.new)
  @signer = args[:signer]
  @options = args
  extend self.class.const_get(package_system.to_s.split("_").map(&:capitalize).join.to_sym)
end

Instance Attribute Details

#optionsHash (readonly)

Returns:

  • (Hash)


23
24
25
# File 'lib/reaper-man/generator.rb', line 23

def options
  @options
end

#package_configHash (readonly)

Returns:

  • (Hash)


19
20
21
# File 'lib/reaper-man/generator.rb', line 19

def package_config
  @package_config
end

#package_systemString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/reaper-man/generator.rb', line 17

def package_system
  @package_system
end

#signerSigner, NilClass (readonly)

Returns:



21
22
23
# File 'lib/reaper-man/generator.rb', line 21

def signer
  @signer
end

Instance Method Details

#compress_file(*path) ⇒ String

Compress a file (gzip)

Parameters:

  • name (String)

    argument list joined to output directory

Returns:

  • (String)

    path to compressed file



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/reaper-man/generator.rb', line 82

def compress_file(*path)
  compressed_path = path.dup
  compressed_path.push("#{compressed_path.pop}.gz")
  base_file = File.open(for_file(path))
  create_file(compressed_path) do |file|
    compressor = Zlib::GzipWriter.new(file)
    while data = base_file.read(2048)
      compressor.write(data)
    end
    compressor.close
  end
end

#create_file(*name) {|path| ... } ⇒ String

Create new file

Parameters:

  • name (String)

    argument list joined to output directory

Yields:

  • block executed with file

Yield Parameters:

  • path (String)

    to file

Returns:

  • (String)

    path to file



50
51
52
53
54
55
56
57
58
59
# File 'lib/reaper-man/generator.rb', line 50

def create_file(*name)
  path = File.join(options[:output_directory], *name)
  FileUtils.mkdir_p(File.dirname(path))
  file = File.open(path, "wb+")
  if block_given?
    yield file
  end
  file.close unless file.closed?
  path
end

#for_file(*name) {|path| ... } ⇒ String

Updates a file

Parameters:

  • name (String)

    argument list joined to output directory

Yields:

  • block executed with file

Yield Parameters:

  • path (String)

    to file

Returns:

  • (String)

    path to file



67
68
69
70
71
72
73
74
75
76
# File 'lib/reaper-man/generator.rb', line 67

def for_file(*name)
  path = File.join(options[:output_directory], *name)
  FileUtils.mkdir_p(File.dirname(path))
  if block_given?
    file = File.open(path, "a+")
    yield file
    file.close
  end
  path
end

#generate!Object

Generate new repository



40
41
42
# File 'lib/reaper-man/generator.rb', line 40

def generate!
  raise NoMethodError.new "Not implemented"
end