Class: Codgen::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/codgen/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 file format: 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

#configObject (readonly)

Returns the value of attribute config.



38
39
40
# File 'lib/codgen/package.rb', line 38

def config
  @config
end

#templatesObject (readonly)

Returns the value of attribute templates.



38
39
40
# File 'lib/codgen/package.rb', line 38

def templates
  @templates
end

#unpacked_pathObject (readonly)

Returns the value of attribute unpacked_path.



38
39
40
# File 'lib/codgen/package.rb', line 38

def unpacked_path
  @unpacked_path
end