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)


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

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)


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

def options
  @options
end

#package_configHash (readonly)

Returns:

  • (Hash)


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

def package_config
  @package_config
end

#package_systemString (readonly)

Returns:

  • (String)


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

def package_system
  @package_system
end

#signerSigner, NilClass (readonly)

Returns:



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

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



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

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



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

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



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

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



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

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