Class: Lambit::Commands::Build::PackageTemplatesCommand

Inherits:
Common::Base
  • Object
show all
Defined in:
lib/lambit/commands/build.rb

Instance Attribute Summary collapse

Attributes inherited from Common::Base

#dry_run, #exitstatus, #run

Instance Method Summary collapse

Methods inherited from Common::Base

#execute, run

Constructor Details

#initialize(opts, args) ⇒ PackageTemplatesCommand

Returns a new instance of PackageTemplatesCommand.



49
50
51
52
53
54
55
# File 'lib/lambit/commands/build.rb', line 49

def initialize(opts, args)
  super
  @workspace = opts['workspace']
  @project_path = opts['project_path']
  @tmpl_name = args[0]
  @tmpl_config = args[1]
end

Instance Attribute Details

#project_pathObject (readonly)

Returns the value of attribute project_path.



45
46
47
# File 'lib/lambit/commands/build.rb', line 45

def project_path
  @project_path
end

#tmpl_configObject (readonly)

Returns the value of attribute tmpl_config.



47
48
49
# File 'lib/lambit/commands/build.rb', line 47

def tmpl_config
  @tmpl_config
end

#tmpl_nameObject (readonly)

Returns the value of attribute tmpl_name.



46
47
48
# File 'lib/lambit/commands/build.rb', line 46

def tmpl_name
  @tmpl_name
end

#workspaceObject (readonly)

Returns the value of attribute workspace.



44
45
46
# File 'lib/lambit/commands/build.rb', line 44

def workspace
  @workspace
end

Instance Method Details

#commandObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/lambit/commands/build.rb', line 57

def command
  tmpl = JSON.parse(File.read("#{self.project_path}/templates/#{self.tmpl_name}"))
  tmpl.merge!(self.tmpl_config) unless self.tmpl_config.nil?

  begin
    File.open("#{self.workspace}/#{self.tmpl_name}",'w') do |f|
      f.write(tmpl.to_json)
    end
    @exitstatus = 0
  rescue Exception => e
    if Lambit.is_debug?
      Lambit.logger.error e
    else
      Lambit.logger.error e.message
    end
    @exitstatus = 1
  end

  return '', self.exitstatus
end