Sha256: 9e3137559d15224478cdaed889304fbf2acc766e75ddf0ba80a1db2487adce3d

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

require 'tty/file'
require 'tty/command'
require 'tty/which'

module Barman
  module ProjectGenerators
    class QA
      attr_reader :project_name, :options, :project_path, :test_path, :templates_path

      def initialize(project_name, options)
        @project_name   = project_name
        @options        = options
        @templates_path = File.join(Barman.templates_path, "qa")
        @project_path   = File.join(".", project_name.to_s)
        @test_path      = File.join(project_path, "test")
      end

      def generate!
        create_project_dir
        create_test_dir
        copy_template_files
        install_gems
      end

      private

      def create_project_dir
        TTY::File.create_dir(project_path)
      end

      def create_test_dir
        TTY::File.create_dir test_path
        create_support_dir
      end

      def create_support_dir
        TTY::File.create_dir File.join(test_path, "support")
      end

      def copy_template_files
        TTY::File.copy_file(File.join(templates_path, "Gemfile"), File.join(project_path, "Gemfile"))
        TTY::File.copy_file(File.join(templates_path, "Rakefile"), File.join(project_path, "Rakefile"))
        TTY::File.copy_file(File.join(templates_path, "test_helper.rb"), File.join(project_path, "test", "test_helper.rb"))
        TTY::File.copy_file(File.join(templates_path, "truth_test.rb"), File.join(project_path, "test", "truth_test.rb"))
        TTY::File.copy_file(File.join(templates_path, "multidevice.rb"), File.join(project_path, "test", "support", "multidevice.rb"))
      end

      def install_gems
        cmd = TTY::Command.new
        unless TTY::Which.exist?('bundle')
          cmd.run("gem install bundler")
        end
        cmd.run("bundle install", chdir: project_path)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
barman-0.1.1 lib/barman/project_generators/qa.rb