Class: FruitToLime::Templating

Inherits:
Object
  • Object
show all
Defined in:
lib/fruit_to_lime/templating.rb

Instance Method Summary collapse

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

#listObject



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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fruit_to_lime/templating.rb', line 13

def unpack(name, path)
    template = list.find { |t| t == name }
    if template
        unpackedname = name

        puts "Unpacking template #{name} to #{path}"
        FileUtils.cp_r File.expand_path(name, @path), path

        # Now make sure all gems in template are installed
        puts "Making sure all needed gems are present"
        Dir.chdir(File.expand_path(unpackedname, path)) do
            exec_but_dont_show_unless_error('bundle install --verbose')
        end
        true
    else
        puts "Unable to find template #{name}"
        false
    end
end