Sha256: 1a3dbe217eb504f2e758f1e7682df4d2a2440f6399c87185ff0b3436bb7e236b

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require 'erb'
require 'pathname'
require 'figs/figsfile'
desc 'Install Fig'
task :install do |task, args|
  base_dir = Pathname.new('.')
  locations = args.extras.empty? ? "application.yml" :  args.extras
  figsfile = Figs::Figsfile.new(*locations)
  
  create_figsfile base_dir, figsfile
  create_non_existent_yaml(figsfile.locations) if figsfile.method.eql?("path")
  
  puts "[Done] Enjoy your figs sir!"
end

def create_figsfile(base_dir, figsfile)
  puts "Figsifying #{base_dir}/ ..."
  file = base_dir.join('Figsfile')
  File.open(file, 'w+') do |f|
    f.write(figsfile.to_yaml)
  end
end

def create_non_existent_yaml(locations)
  locations.each do |file|
    if !File.exists?(file) && !Dir.exists?(file)
      puts "[Add] #{file} does not exist, creating."
      application_yml = File.expand_path("../../templates/application.yml", __FILE__)
      File.open(file, 'w+') do |f|
        f.write(ERB.new(File.read(application_yml)).result(binding))
        ignore_configuration(f.path)
      end
    end
  end
end

def ignore_configuration(application_yml)
  if File.exists?(".gitignore")
    File.open('.gitignore', 'a') do |file|
      file.write(<<-EOF)
# Ignore application configuration
#{application_yml}
EOF
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
figs-3.0.0 lib/figs/tasks/install.rake
figs-2.1.1 lib/figs/tasks/install.rake
figs-2.0.4 lib/figs/tasks/install.rake
figs-2.0.3 lib/figs/tasks/install.rake
figs-2.0.2 lib/figs/tasks/install.rake
figs-2.0.1 lib/figs/tasks/install.rake
figs-2.0.0 lib/figs/tasks/install.rake