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
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] = args extend self.class.const_get(package_system.to_s.split('_').map(&:capitalize).join.to_sym) end |
Instance Attribute Details
#options ⇒ Hash (readonly)
24 25 26 |
# File 'lib/reaper-man/generator.rb', line 24 def end |
#package_config ⇒ Hash (readonly)
20 21 22 |
# File 'lib/reaper-man/generator.rb', line 20 def package_config @package_config end |
#package_system ⇒ String (readonly)
18 19 20 |
# File 'lib/reaper-man/generator.rb', line 18 def package_system @package_system end |
#signer ⇒ Signer, NilClass (readonly)
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)
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
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([: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
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([: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 |