Class: PackageGenerator::Generator
- Inherits:
-
Object
- Object
- PackageGenerator::Generator
- Defined in:
- lib/packagegenerator/generator.rb
Instance Attribute Summary collapse
-
#copyright ⇒ Object
writeonly
Sets the attribute copyright.
-
#description ⇒ Object
writeonly
Sets the attribute description.
-
#install_items ⇒ Object
writeonly
Sets the attribute install_items.
-
#license ⇒ Object
writeonly
Sets the attribute license.
-
#package_name ⇒ Object
writeonly
Sets the attribute package_name.
-
#postinstall_commands ⇒ Object
writeonly
Sets the attribute postinstall_commands.
-
#preinstall_commands ⇒ Object
writeonly
Sets the attribute preinstall_commands.
-
#readme ⇒ Object
writeonly
Sets the attribute readme.
-
#vendor ⇒ Object
writeonly
Sets the attribute vendor.
-
#version ⇒ Object
writeonly
Sets the attribute version.
Instance Method Summary collapse
- #add_directory_contents(target_path, directory_path, exclude = []) ⇒ Object
- #add_install_item(item) ⇒ Object
- #generate(output = $stdout) ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
- #write_install_items(output) ⇒ Object
- #write_postinstall(output) ⇒ Object
- #write_preinstall(output) ⇒ Object
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
8 9 10 11 12 |
# File 'lib/packagegenerator/generator.rb', line 8 def initialize @license = 'LICENSE' @readme = 'README' @install_items = [] end |
Instance Attribute Details
#copyright=(value) ⇒ Object (writeonly)
Sets the attribute copyright
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def copyright=(value) @copyright = value end |
#description=(value) ⇒ Object (writeonly)
Sets the attribute description
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def description=(value) @description = value end |
#install_items=(value) ⇒ Object (writeonly)
Sets the attribute install_items
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def install_items=(value) @install_items = value end |
#license=(value) ⇒ Object (writeonly)
Sets the attribute license
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def license=(value) @license = value end |
#package_name=(value) ⇒ Object (writeonly)
Sets the attribute package_name
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def package_name=(value) @package_name = value end |
#postinstall_commands=(value) ⇒ Object (writeonly)
Sets the attribute postinstall_commands
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def postinstall_commands=(value) @postinstall_commands = value end |
#preinstall_commands=(value) ⇒ Object (writeonly)
Sets the attribute preinstall_commands
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def preinstall_commands=(value) @preinstall_commands = value end |
#readme=(value) ⇒ Object (writeonly)
Sets the attribute readme
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def readme=(value) @readme = value end |
#vendor=(value) ⇒ Object (writeonly)
Sets the attribute vendor
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def vendor=(value) @vendor = value end |
#version=(value) ⇒ Object (writeonly)
Sets the attribute version
6 7 8 |
# File 'lib/packagegenerator/generator.rb', line 6 def version=(value) @version = value end |
Instance Method Details
#add_directory_contents(target_path, directory_path, exclude = []) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/packagegenerator/generator.rb', line 18 def add_directory_contents(target_path, directory_path, exclude=[]) directory_search=File.join(directory_path, '**', '*') directory_pathname=Pathname.new(directory_path) search_files = Dir.glob(directory_search) exclude.each do |excluded_item| search_files.delete excluded_item end search_files.each do |file_name| if File.file?(file_name) install_file = PackageGenerator::InstallFile.new install_file.source = file_name install_file.mode = Integer("%o" % (File.lstat(file_name).mode & 0777)) file_pathname = Pathname.new(file_name) relative_path = file_pathname.relative_path_from(directory_pathname) install_file.target = File.join(target_path, relative_path) add_install_item install_file end end end |
#add_install_item(item) ⇒ Object
14 15 16 |
# File 'lib/packagegenerator/generator.rb', line 14 def add_install_item(item) @install_items << item end |
#generate(output = $stdout) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/packagegenerator/generator.rb', line 46 def generate(output=$stdout) raise ArgumentError, 'package_name cannot be nil.' if @package_name.nil? raise ArgumentError, 'copyright cannot be nil.' if @copyright.nil? raise ArgumentError, 'vendor cannot be nil.' if @vendor.nil? raise ArgumentError, 'license cannot be nil.' if @license.nil? raise ArgumentError, 'readme cannot be nil.' if @readme.nil? raise ArgumentError, 'description cannot be nil.' if @description.nil? raise ArgumentError, 'version cannot be nil.' if @version.nil? output.write "%product #{@package_name}\n" output.write "%copyright #{@copyright}\n" output.write "%vendor #{@vendor}\n" output.write "%license #{@license}\n" output.write "%readme #{@readme}\n" output.write "%description #{@description}\n" output.write "%version #{@version}\n" write_preinstall(output) if @preinstall_commands.is_a?(Array) write_postinstall(output) if @postinstall_commands.is_a?(Array) write_install_items(output) if @install_items.is_a?(Array) && @install_items.length > 0 end |
#write_install_items(output) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/packagegenerator/generator.rb', line 103 def write_install_items(output) output.write "\n" @install_items.each do |install_file| if(install_file.is_a?(InstallItem)) install_file.write(output) end end end |
#write_postinstall(output) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/packagegenerator/generator.rb', line 86 def write_postinstall(output) output.write "\n" postinstall_index = 0 @postinstall_commands.each do |postinstall_command| output.write "%postinstall " if postinstall_command =~ /\n/ output.write "<< EOF#{postinstall_index}\n" output.write "#{postinstall_command}\n" output.write "EOF#{postinstall_index}\n" else output.write "#{postinstall_command}\n" end postinstall_index += 1 end end |
#write_preinstall(output) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/packagegenerator/generator.rb', line 69 def write_preinstall(output) output.write "\n" preinstall_index = 0 @preinstall_commands.each do |preinstall_command| output.write "%preinstall " if preinstall_command =~ /\n/ output.write "<< EOF#{preinstall_index}\n" output.write "#{preinstall_command}\n" output.write "EOF#{preinstall_index}\n" else output.write "#{preinstall_command}\n" end preinstall_index += 1 end end |