Class: Template
- Inherits:
-
Object
- Object
- Template
- Defined in:
- lib/opening_act/template.rb
Overview
Class for template and boilerplate files
Constant Summary collapse
- PROJECT_TEMPLATE =
File.('../templates', __FILE__)
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#test_type ⇒ Object
readonly
Returns the value of attribute test_type.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(name, type) ⇒ Template
constructor
A new instance of Template.
- #initiate_project ⇒ Object
- #remove_extra_files ⇒ Object
- #rename_files ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/opening_act/template.rb', line 4 def name @name end |
#test_type ⇒ Object (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
#create ⇒ Object
13 14 15 |
# File 'lib/opening_act/template.rb', line 13 def create FileUtils.copy_entry PROJECT_TEMPLATE, name end |
#initiate_project ⇒ Object
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_files ⇒ Object
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_files ⇒ Object
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 |