class Dopstick::Generator::Gem::Generator

Attributes

options[RW]

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 16
def self.exit_on_failure?
  true
end
source_paths() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 20
def self.source_paths
  [
    source_root,
    File.join(__dir__, "../base/templates")
  ]
end
source_root() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 27
def self.source_root
  File.join(__dir__, "templates")
end

Public Instance Methods

bundle_install() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 97
def bundle_install
  return if options.skip_install?

  in_root do
    run "bundle install"
  end
end
copy_active_record_files() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 91
def copy_active_record_files
  return unless options[:active_record]

  template "active_record.erb", "test/support/active_record.rb"
end
copy_binary_files() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 81
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_bins() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 58
def copy_bins
  template "console.erb", "bin/console"
  template "setup.erb", "bin/setup"
  in_root { run "chmod +x bin/*" }
end
copy_generic_templates() click to toggle source
# 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_templates() click to toggle source
# 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 "dependabot.erb", ".github/dependabot.yml"
  template "codeowners.erb", ".github/CODEOWNERS"
end
copy_ruby_templates() click to toggle source
# 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_files() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 76
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_file() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 64
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_file() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 72
def create_version_file
  template "version.erb", "lib/#{options.entry_path}/version.rb"
end
erb(file) click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 151
def erb(file)
  ERB.new(
    File.read("#{self.class.source_root}/#{file}")
  ).result(binding)
end
initialize_repo() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 105
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
render_cli() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 132
def render_cli
  cli_class = erb("cli_class.erb")
              .chomp
              .gsub(/^(.)/m, "#{'  ' * options.namespace_size}\\1")

  render_tree(true) { cli_class }
end
render_generator() click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 140
def render_generator
  generator_class = erb("generator_class.erb")
                    .chomp
                    .gsub(
                      /^(.)/m,
                      "#{'  ' * options.namespace_size}\\1"
                    )

  render_tree(true) { generator_class }
end
render_tree(skip_content_spaces = false) { || ... } click to toggle source
# File lib/dopstick/generator/gem/generator.rb, line 114
def render_tree(skip_content_spaces = false)
  content = []

  options.namespace_names.each_with_index do |name, count|
    content << ("  " * count) + "module #{name}"
  end

  spacer = skip_content_spaces ? "" : "  "

  content << (spacer * options.namespace_size) + yield

  (options.namespace_size - 1).downto(0) do |count|
    content << "#{'  ' * count}end"
  end

  content.join("\n")
end