Class: Dopstick::Generator::Gem::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/dopstick/generator/gem/generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/dopstick/generator/gem/generator.rb', line 12

def options
  @options
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/dopstick/generator/gem/generator.rb', line 16

def self.exit_on_failure?
  true
end

.source_pathsObject



20
21
22
23
24
25
# File 'lib/dopstick/generator/gem/generator.rb', line 20

def self.source_paths
  [
    source_root,
    File.join(__dir__, "../base/templates")
  ]
end

.source_rootObject



27
28
29
# File 'lib/dopstick/generator/gem/generator.rb', line 27

def self.source_root
  File.join(__dir__, "templates")
end

Instance Method Details

#bundle_installObject



99
100
101
102
103
104
105
# File 'lib/dopstick/generator/gem/generator.rb', line 99

def bundle_install
  return if options.skip_install?

  in_root do
    run "bundle install"
  end
end

#copy_active_record_filesObject



93
94
95
96
97
# File 'lib/dopstick/generator/gem/generator.rb', line 93

def copy_active_record_files
  return unless options[:active_record]

  template "active_record.erb", "test/support/active_record.rb"
end

#copy_binary_filesObject



83
84
85
86
87
88
89
90
91
# File 'lib/dopstick/generator/gem/generator.rb', line 83

def copy_binary_files
  return unless options.bin?

  template "cli.erb", "lib/#{options.entry_path}/cli.rb"
  template "generator.erb", "lib/#{options.entry_path}/generator.rb"
  template "bin.erb", "exe/#{options.bin}"
  create_file "lib/#{options.entry_path}/templates/.keep"
  in_root { run "chmod +x exe/*" }
end

#copy_binsObject



60
61
62
63
64
# File 'lib/dopstick/generator/gem/generator.rb', line 60

def copy_bins
  template "console.erb", "bin/console"
  template "setup.erb", "bin/setup"
  in_root { run "chmod +x bin/*" }
end

#copy_generic_templatesObject



39
40
41
42
43
44
45
46
# File 'lib/dopstick/generator/gem/generator.rb', line 39

def copy_generic_templates
  template "license.erb", "LICENSE.md"
  template "coc.erb", "CODE_OF_CONDUCT.md"
  template "readme.erb", "README.md"
  template "changelog.erb", "CHANGELOG.md"
  template "contributing.erb", "CONTRIBUTING.md"
  template "gitignore.erb", ".gitignore"
end

#copy_github_templatesObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dopstick/generator/gem/generator.rb', line 48

def copy_github_templates
  template "funding.erb", ".github/FUNDING.yml"
  template "bug_report.erb", ".github/ISSUE_TEMPLATE/bug_report.md"
  template "feature_request.erb",
           ".github/ISSUE_TEMPLATE/feature_request.md"
  template "pull_request.erb", ".github/PULL_REQUEST_TEMPLATE.md"
  template "issue_template_config.erb",
           ".github/ISSUE_TEMPLATE/config.yml"
  template "dependabot.erb", ".github/dependabot.yml"
  template "codeowners.erb", ".github/CODEOWNERS"
end

#copy_ruby_templatesObject



31
32
33
34
35
36
37
# File 'lib/dopstick/generator/gem/generator.rb', line 31

def copy_ruby_templates
  template "gemspec.erb", "#{options.package_name}.gemspec"
  template "rakefile.erb", "Rakefile"
  template "rubocop.erb", ".rubocop.yml"
  template "gemfile.erb", "Gemfile"
  template "tests_workflow.erb", ".github/workflows/ruby-tests.yml"
end

#copy_test_filesObject



78
79
80
81
# File 'lib/dopstick/generator/gem/generator.rb', line 78

def copy_test_files
  template "test_helper.erb", "test/test_helper.rb"
  template "test_file.erb", "test/#{options.entry_path}_test.rb"
end

#create_entry_fileObject



66
67
68
69
70
71
72
# File 'lib/dopstick/generator/gem/generator.rb', line 66

def create_entry_file
  if options.entry_path.include?("/")
    template "gem_entry_file.erb", "lib/#{options.package_name}.rb"
  end

  template "entry_file.erb", "lib/#{options.entry_path}.rb"
end

#create_version_fileObject



74
75
76
# File 'lib/dopstick/generator/gem/generator.rb', line 74

def create_version_file
  template "version.erb", "lib/#{options.entry_path}/version.rb"
end

#initialize_repoObject



107
108
109
110
111
112
113
# File 'lib/dopstick/generator/gem/generator.rb', line 107

def initialize_repo
  in_root do
    run "git init --initial-branch=main", capture: true
    run "git add bin --force", capture: true
    run "git add .", capture: true
  end
end