Class: RBCliTool::Extern

Inherits:
Generator show all
Defined in:
lib/rbcli-tool/generators.rb

Instance Method Summary collapse

Methods inherited from Generator

inherited

Constructor Details

#initialize(root_path, template_vars) ⇒ Extern

Returns a new instance of Extern.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rbcli-tool/generators.rb', line 54

def initialize root_path, template_vars
  @filepaths = [
      {
          src: "#{File.dirname(__FILE__)}/../../skeletons/project/application/commands/script.erb",
          dest: "#{root_path}/application/commands/#{template_vars[:name]}.rb"
      }, {
          src: "#{File.dirname(__FILE__)}/../../skeletons/project/application/commands/scripts/script.sh",
          dest: "#{root_path}/application/commands/scripts/#{template_vars[:name]}.sh",
          perms: 0755
      }
  ]
  @template_vars = template_vars
  #@template_vars[:libsh_path] = Pathname.new("#{File.dirname(__FILE__)}/../../lib-sh/lib-rbcli.sh").cleanpath.to_s  # We clean this path because it will be visible to the user
end

Instance Method Details

#runObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rbcli-tool/generators.rb', line 69

def run
  confirmed = false
  @filepaths.each do |file|
    next if file[:dest].end_with? '.sh' and @template_vars[:no_script]
    if File.exist? file[:dest]
      RBCliTool.continue_confirmation "The script command #{@template_vars[:name]} already exists; contents will be overwritten." unless confirmed
      confirmed = true
      FileUtils.rm_rf file[:dest]
    end
    RBCliTool.cp_file file[:src], file[:dest], @template_vars
    File.chmod file[:perms], file[:dest] if file.key? :perms
  end
end