Module: QAT::Web::Generator

Extended by:
FileUtils
Includes:
FileUtils
Defined in:
lib/qat/web/generator.rb

Overview

Module for the various generators used in the CLI utility

Since:

  • 6.1.0

Class Method Summary collapse

Class Method Details

.add_gem_dependency(gemfile_path, gem, opts = {}) ⇒ Object

Since:

  • 6.1.0



43
44
45
46
47
48
# File 'lib/qat/web/generator.rb', line 43

def add_gem_dependency (gemfile_path, gem, opts = {})
  version = opts[:version]
  line = "\n\ngem '#{gem}'#{version ? ", '>= #{version}'" : ''}"
  puts "adding dependencies #{gem} to Gemfile" if opts[:verbose]
  write_to_gemfile gemfile_path, line
end

.add_module(stdout, opts) ⇒ Object

Adds a files QAT Web module to the current project

Since:

  • 6.1.0



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/qat/web/generator.rb', line 12

def add_module(stdout, opts)
  stdout.puts "Adding files to project" if opts[:verbose]

  # Read GemFile of new project
  path = File.join(Dir.pwd, 'Gemfile')
  has_qatweb = verify_gems path, 'qat-web', verbose: opts[:verbose]
  if has_qatweb
    puts "Module already integrated"
  else
    add_gem_dependency path, 'qat-web', verbose: opts[:verbose], version: QAT::Web::VERSION
    add_gem_dependency path, 'headless', verbose: opts[:verbose]
    add_gem_dependency path, 'selenium-webdriver', verbose: opts[:verbose]
    cp_r ::File.join(::File.dirname(__FILE__), 'generator', 'project', '.'), Dir.pwd, opts
  end
end

.verify_gems(gemfile_path, gem, opts = {}) ⇒ Object

Since:

  • 6.1.0



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/qat/web/generator.rb', line 28

def verify_gems (gemfile_path, gem, opts = {})
  file = File.read(gemfile_path)
  gemfile = Gemnasium::Parser.gemfile(file)
  dependencies = gemfile.dependencies
  found_gem = dependencies.find {|i| i.name == gem}
  puts "Found gem: #{found_gem}"
  puts "gem #{gem} found? #{!found_gem.nil?}" if opts[:verbose]

  if found_gem
    return true
  else
    return false
  end
end

.write_to_gemfile(filename, line) ⇒ Object

Since:

  • 6.1.0



51
52
53
# File 'lib/qat/web/generator.rb', line 51

def write_to_gemfile filename, line
  ::File.write(filename, line, mode: 'a')
end