Class: Codgen::Package
- Inherits:
-
Object
- Object
- Codgen::Package
- Defined in:
- lib/codgen/package.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
-
#unpacked_path ⇒ Object
readonly
Returns the value of attribute unpacked_path.
Instance Method Summary collapse
-
#initialize(package_info) ⇒ Package
constructor
A new instance of Package.
Constructor Details
#initialize(package_info) ⇒ Package
Returns a new instance of Package.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/codgen/package.rb', line 8 def initialize(package_info) if package_info.is_a?(String) @input_path = package_info elsif package_info.is_a?(Hash) @input_path = package_info['path'] if @input_path == nil Logger.error 'Required property of package "path" was not found' end else Logger.error 'Invalid package path format' end @unpacked_path = '' if File.directory?(@input_path) @unpacked_path = @input_path elsif File.extname(@input_path) == '.zip' @unpacked_path = File.basename(@input_path, '.zip') unzip_file(@input_path) else Logger.error "Invalid package #{@input_path}: should be a zip or a directory" end config_path = "#{@unpacked_path}/config.json" config_file = File.read(config_path) @config = JSON.parse(config_file) @templates = @config['templates'] @templates.each { |t| t['in'] = "#{@unpacked_path}/templates/#{t['in']}"} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
38 39 40 |
# File 'lib/codgen/package.rb', line 38 def config @config end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
38 39 40 |
# File 'lib/codgen/package.rb', line 38 def templates @templates end |
#unpacked_path ⇒ Object (readonly)
Returns the value of attribute unpacked_path.
38 39 40 |
# File 'lib/codgen/package.rb', line 38 def unpacked_path @unpacked_path end |