Class: FruitToLime::Templating
- Inherits:
-
Object
- Object
- FruitToLime::Templating
- Defined in:
- lib/fruit_to_lime/templating.rb
Instance Method Summary collapse
- #exec_but_dont_show_unless_error(cmd) ⇒ Object
-
#initialize(path) ⇒ Templating
constructor
A new instance of Templating.
- #list ⇒ Object
- #unpack(name, path) ⇒ Object
Constructor Details
#initialize(path) ⇒ Templating
Returns a new instance of Templating.
5 6 7 |
# File 'lib/fruit_to_lime/templating.rb', line 5 def initialize(path) @path = path end |
Instance Method Details
#exec_but_dont_show_unless_error(cmd) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fruit_to_lime/templating.rb', line 13 def exec_but_dont_show_unless_error(cmd) std_out_value = [] Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| while std_line = stdout.gets std_out_value << std_line end exit_status = wait_thr.value if !exit_status.success? puts "Failed with #{exit_status}" puts "std_out_value" puts std_out_value raise "failed exec #{cmd}" end end end |
#list ⇒ Object
9 10 11 |
# File 'lib/fruit_to_lime/templating.rb', line 9 def list() Dir.entries(@path).select { |d| d != '.' && d != '..' } end |
#unpack(name, path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fruit_to_lime/templating.rb', line 31 def unpack(name, path) template = list.find { |t| t == name } if template unpackedname = name puts "Unpacking template #{name} to #{path}" FileUtils.cp_r File.(name, @path), path # Now make sure all gems in template are installed puts "Making sure all needed gems are present" Dir.chdir(File.(unpackedname, path)) do exec_but_dont_show_unless_error('bundle install --verbose') end true else puts "Unable to find template #{name}" false end end |