Class: ReaperMan::Generator
- Inherits:
-
Object
- Object
- ReaperMan::Generator
- 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
Instance Attribute Summary collapse
- #options ⇒ Hash readonly
- #package_config ⇒ Hash readonly
- #package_system ⇒ String readonly
- #signer ⇒ Signer, NilClass readonly
Instance Method Summary collapse
-
#compress_file(*path) ⇒ String
Compress a file (gzip).
-
#create_file(*name) {|path| ... } ⇒ String
Create new file.
-
#for_file(*name) {|path| ... } ⇒ String
Updates a file.
-
#generate! ⇒ Object
Generate new repository.
-
#initialize(args = {}) ⇒ Generator
constructor
Create new instance.
Methods included from Utils::Checksum
Constructor Details
#initialize(args = {}) ⇒ Generator
Create new instance
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
#options ⇒ Hash (readonly)
23 24 25 |
# File 'lib/reaper-man/generator.rb', line 23 def @options end |
#package_config ⇒ Hash (readonly)
19 20 21 |
# File 'lib/reaper-man/generator.rb', line 19 def package_config @package_config end |
#package_system ⇒ String (readonly)
17 18 19 |
# File 'lib/reaper-man/generator.rb', line 17 def package_system @package_system end |
#signer ⇒ Signer, NilClass (readonly)
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)
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
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([: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
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([: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 |