Class: Spiker::Generators::Multi

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/spiker/generators/multi.rb

Overview

Generates multiple spike files, seperating tests from the tested code. For when the spike gets too hairy for a single file.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



16
17
18
# File 'lib/spiker/generators/multi.rb', line 16

def self.source_root
  "#{File.dirname(__FILE__)}/templates/multi"
end

Instance Method Details

#create_app_filesObject



34
35
36
37
38
# File 'lib/spiker/generators/multi.rb', line 34

def create_app_files
  name_in_snake_case = Spiker.snake_case(name)
  opts = { name_as_class: Spiker.classify(name) }
  template("app.rb.erb", "#{name}/lib/#{name_in_snake_case}.rb", opts)
end

#create_env_fileObject



57
58
59
# File 'lib/spiker/generators/multi.rb', line 57

def create_env_file
  template("../common/basic.env", "#{name}/.env")
end

#create_gem_fileObject



44
45
46
# File 'lib/spiker/generators/multi.rb', line 44

def create_gem_file
  template("gemfile.rb", "#{name}/Gemfile")
end

#create_guard_fileObject



40
41
42
# File 'lib/spiker/generators/multi.rb', line 40

def create_guard_file
  template("guardfile.rb", "#{name}/Guardfile")
end

#create_rake_fileObject



48
49
50
# File 'lib/spiker/generators/multi.rb', line 48

def create_rake_file
  template("rakefile.rb", "#{name}/Rakefile")
end

#create_readme_fileObject



52
53
54
55
# File 'lib/spiker/generators/multi.rb', line 52

def create_readme_file
  opts = { name_as_class: Spiker.classify(name), name: }
  template("readme.md.erb", "#{name}/README.md", opts)
end

#create_spike_directoriesObject



20
21
22
23
24
# File 'lib/spiker/generators/multi.rb', line 20

def create_spike_directories
  empty_directory(name)
  empty_directory("#{name}/lib")
  empty_directory("#{name}/test")
end

#create_test_filesObject



26
27
28
29
30
31
32
# File 'lib/spiker/generators/multi.rb', line 26

def create_test_files
  name_in_snake_case = Spiker.snake_case(name)
  name_as_class = Spiker.classify(name)
  opts = { name_as_class:, name_in_snake_case: }
  template("app_test.rb.erb", "#{name}/test/#{name_in_snake_case}_test.rb", opts)
  template("test_helper.rb", "#{name}/test/test_helper.rb", opts)
end

#run_bundlerObject



61
62
63
64
65
# File 'lib/spiker/generators/multi.rb', line 61

def run_bundler
  inside(name) do
    run("bundle install")
  end
end