Class: Template

Inherits:
Object
  • Object
show all
Defined in:
lib/opening_act/template.rb

Overview

Class for template and boilerplate files

Constant Summary collapse

PROJECT_TEMPLATE =
File.expand_path('../templates', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Template

Returns a new instance of Template.



8
9
10
11
# File 'lib/opening_act/template.rb', line 8

def initialize(name, type)
  @name = name
  @test_type = type[1..-1]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/opening_act/template.rb', line 4

def name
  @name
end

#test_typeObject (readonly)

Returns the value of attribute test_type.



3
4
5
# File 'lib/opening_act/template.rb', line 3

def test_type
  @test_type
end

Instance Method Details

#createObject



13
14
15
# File 'lib/opening_act/template.rb', line 13

def create
  FileUtils.copy_entry PROJECT_TEMPLATE, name
end

#initiate_projectObject



17
18
19
20
21
22
23
# File 'lib/opening_act/template.rb', line 17

def initiate_project
  Dir.chdir name do
    `git init`
    `gem install bundler`
    `bundle install`
  end
end

#remove_extra_filesObject



38
39
40
41
42
43
# File 'lib/opening_act/template.rb', line 38

def remove_extra_files
  other_test_type = test_type == 'rspec' ? 'test' : 'spec'

  FileUtils.rm_rf("#{name}/#{other_test_type}")
  FileUtils.rm Dir.glob("#{name}/*_#{other_test_type}")
end

#rename_filesObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/opening_act/template.rb', line 25

def rename_files
  File.rename("#{name}/new_app.rb", "#{name}/#{name}.rb")

  case test_type
  when 'minitest'
    File.rename("#{name}/test/new_app_test.rb", "#{name}/test/#{name}_test.rb")
  when 'rspec'
    File.rename("#{name}/spec/new_app_spec.rb", "#{name}/spec/#{name}_spec.rb")
  end

  remove_test_suffix
end