-
# frozen_string_literal: true
-
-
1
require "zeitwerk"
-
-
1
Zeitwerk::Loader.new.then do |loader|
-
1
loader.inflector.inflect "cli" => "CLI",
-
"ci" => "CI",
-
"circle_ci" => "CircleCI",
-
"dcoo" => "DCOO",
-
"erb" => "ERB",
-
"git_hub_ci" => "GitHubCI",
-
"irb_kit" => "IRBKit",
-
"rspec" => "RSpec",
-
"rtc" => "RTC"
-
1
loader.tag = File.basename __FILE__, ".rb"
-
1
loader.push_dir __dir__
-
1
loader.setup
-
end
-
-
# Main namespace.
-
1
module Rubysmith
-
1
def self.loader registry = Zeitwerk::Registry
-
6
@loader ||= registry.loaders.each.find { |loader| loader.tag == File.basename(__FILE__, ".rb") }
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "open3"
-
1
require "refinements/pathname"
-
-
1
module Rubysmith
-
# :reek:DataClump
-
# Provides common functionality necessary for all builders.
-
1
class Builder
-
1
include Dependencies[:logger]
-
-
1
using Refinements::Pathname
-
-
1
HELPERS = {inserter: Text::Inserter, renderer: Renderers::ERB, executor: Open3}.freeze
-
-
1
def initialize(settings, helpers: HELPERS, **)
-
313
@settings = settings
-
313
@helpers = helpers
-
313
super(**)
-
end
-
-
1
def append content
-
12
log_debug "Appending content to: #{relative_build_path}"
-
24
build_path.rewrite { |body| body + content }
-
12
self
-
end
-
-
1
def check
-
8
build_path.then do |path|
-
8
then: 1
else: 7
path.exist? ? logger.abort("Path exists: #{path}.") : log_debug("Checked: #{path}.")
-
end
-
end
-
-
1
def delete
-
3
log_info "Deleting: #{relative_build_path}"
-
3
build_path.delete
-
3
self
-
end
-
-
1
def insert_after pattern, content
-
28
log_debug "Inserting content after pattern in: #{relative_build_path}"
-
28
build_path.write inserter.new(build_path.readlines, :after).call(content, pattern).join
-
28
self
-
end
-
-
1
def insert_before pattern, content
-
20
log_debug "Inserting content before pattern in: #{relative_build_path}"
-
20
build_path.write inserter.new(build_path.readlines, :before).call(content, pattern).join
-
20
self
-
end
-
-
1
def make_path
-
8
log_info "Making: #{relative_build_path}"
-
8
build_path.mkpath
-
8
self
-
end
-
-
1
def permit mode
-
48
log_debug "Changing permissions for: #{relative_build_path}"
-
48
build_path.chmod mode
-
48
self
-
end
-
-
1
def prepend content
-
3
log_debug "Prepending content to: #{relative_build_path}"
-
6
build_path.rewrite { |body| content + body }
-
3
self
-
end
-
-
1
def rename name
-
20
log_debug "Renaming: #{build_path.basename} to #{name}"
-
20
build_path.rename build_path.parent.join(name)
-
20
self
-
end
-
-
1
def render
-
270
log_info "Rendering: #{relative_build_path}"
-
-
270
pathway.start_path.read.then do |content|
-
270
build_path.make_ancestors.write renderer.call(content)
-
end
-
-
270
self
-
end
-
-
1
def replace pattern, content
-
300
log_debug "Replacing content for patterns in: #{relative_build_path}"
-
600
build_path.rewrite { |body| body.gsub pattern, content }
-
300
self
-
end
-
-
1
def run *command
-
18
log_info "Running: #{command}"
-
18
execute(*command)
-
16
self
-
rescue StandardError => error
-
2
log_error error and self
-
end
-
-
1
def touch
-
4
log_info "Touching: #{relative_build_path}"
-
4
build_path.touch_deep
-
4
self
-
end
-
-
1
private
-
-
1
attr_reader :settings, :helpers
-
-
1
def execute *command
-
18
executor.capture2e(*command).then do |result, status|
-
16
else: 14
then: 2
log_error result unless status.success?
-
end
-
end
-
-
1
def inserter = helpers.fetch(__method__)
-
-
1
def renderer = helpers.fetch(__method__).new(settings)
-
-
1
def executor = helpers.fetch(__method__)
-
-
1
def relative_build_path = build_path.relative_path_from(settings.target_root)
-
-
1
def build_path
-
1508
pathway.end_path
-
.gsub("%project_name%", settings.project_name)
-
.sub("%project_path%", settings.project_path)
-
.sub ".erb", ""
-
end
-
-
1
def pathway = settings.pathway
-
-
304
def log_info(message) = logger.info { message }
-
-
439
def log_debug(message) = logger.debug { message }
-
-
5
def log_error(message) = logger.error { message }
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Rubysmith
-
1
module Builders
-
# Provides default implementation from which builders can inherit from.
-
1
class Abstract
-
1
include Dependencies[:settings, :logger]
-
-
1
def initialize(builder: Builder, **)
-
628
@builder = -> settings { builder.new settings, logger: }
-
361
super(**)
-
end
-
-
1
def call
-
1
fail NoMethodError,
-
"`#{self.class}##{__method__} #{method(__method__).parameters}` must be implemented."
-
end
-
-
1
protected
-
-
1
attr_reader :builder
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds Bundler Gemfile configuration for project skeleton.
-
1
class Bundler < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
24
builder.call(settings.with(template_path: "%project_name%/Gemfile.erb"))
-
.render
-
.replace(/\n\s+group/, "\n\ngroup")
-
.replace(/\n\s+gem/, "\n gem")
-
.replace(/ (?=.+(bootsnap|dry-monads|refinements|zeitwerk))/, "")
-
.replace(/(\n+|\s+)end/, "\nend")
-
.replace(/\n\ngroup :(quality|development|test|tools) do\nend/, "")
-
.insert_after(/source.+"\n/, "\n")
-
-
24
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds project skeleton with Caliber style support.
-
1
class Caliber < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
11
else: 6
then: 5
return false unless settings.build_caliber
-
-
6
builder.call(settings.with(template_path: "%project_name%/bin/rubocop.erb"))
-
.render
-
.permit 0o755
-
-
6
path = "%project_name%/.config/rubocop/config.yml.erb"
-
6
builder.call(settings.with(template_path: path)).render
-
6
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds project skeleton Circle CI configuration.
-
1
class CircleCI < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
else: 5
then: 4
return false unless settings.build_circle_ci
-
-
5
builder.call(settings.with(template_path: "%project_name%/.circleci/config.yml.erb"))
-
.render
-
.replace(/\n\n\Z/, "\n")
-
-
5
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds project skeleton console for object inspection and exploration.
-
1
class Console < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
11
else: 7
then: 4
return false unless settings.build_console
-
-
7
builder.call(settings.with(template_path: "%project_name%/bin/console.erb"))
-
.render
-
.permit 0o755
-
-
7
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/string"
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds project skeleton core structure and minimum file support.
-
1
class Core < Abstract
-
1
using Refinements::String
-
1
using Refinements::Struct
-
-
1
def call
-
16
render_implementation
-
16
render_specification
-
16
true
-
end
-
-
1
private
-
-
1
def render_implementation
-
16
builder.call(settings.with(template_path: "%project_name%/lib/%project_path%.rb.erb"))
-
.render
-
.replace(" require", "require")
-
.replace(/ (?=(Zeit|loader|end))/, "")
-
.replace("\n \n", "\n\n")
-
.insert_before("module #{module_name}", "#{indentation}# Main namespace.\n")
-
end
-
-
1
def render_specification
-
16
else: 8
then: 8
return unless settings.build_zeitwerk
-
-
8
path = "%project_name%/spec/lib/%project_path%_spec.rb.erb"
-
8
builder.call(settings.with(template_path: path)).render
-
end
-
-
1
def indentation = ::Core::EMPTY_STRING.indent settings.project_levels
-
-
1
def module_name = settings.project_class
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module DevContainer
-
# Builds Docker Compose configuration for container.
-
1
class Compose < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_devcontainer
-
-
4
path = "%project_name%/.devcontainer/compose.yaml.erb"
-
4
builder.call(settings.with(template_path: path)).render
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module DevContainer
-
# Builds container configuration.
-
1
class Configuration < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
10
else: 6
then: 4
return false unless settings.build_devcontainer
-
-
6
path = "%project_name%/.devcontainer/devcontainer.json.erb"
-
6
builder.call(settings.with(template_path: path)).render
-
6
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module DevContainer
-
# Builds Dockerfile for container.
-
1
class Dockerfile < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_devcontainer
-
-
4
builder.call(settings.with(template_path: "%project_name%/.devcontainer/Dockerfile.erb"))
-
.render
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Docker
-
# Builds Docker build script.
-
1
class Build < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
else: 5
then: 4
return false unless settings.build_docker
-
-
5
builder.call(settings.with(template_path: "%project_name%/bin/docker/build.erb"))
-
.render
-
.permit 0o755
-
-
5
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Docker
-
# Builds Docker compose configuration.
-
1
class Compose < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_docker
-
-
4
builder.call(settings.with(template_path: "%project_name%/compose.yml.erb")).render
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Docker
-
# Builds Docker console script.
-
1
class Console < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
else: 5
then: 4
return false unless settings.build_docker
-
-
5
builder.call(settings.with(template_path: "%project_name%/bin/docker/console.erb"))
-
.render
-
.permit 0o755
-
-
5
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Docker
-
# Builds Docker entrypoint script.
-
1
class Entrypoint < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
else: 5
then: 4
return false unless settings.build_docker
-
-
5
builder.call(settings.with(template_path: "%project_name%/bin/docker/entrypoint.erb"))
-
.render
-
.permit 0o755
-
-
5
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Docker
-
# Builds Dockerfile configuration.
-
1
class File < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
15
else: 11
then: 4
return false unless settings.build_docker
-
-
11
builder.call(settings.with(template_path: "%project_name%/Dockerfile.erb")).render
-
11
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Docker
-
# Builds Docker ignore configuration.
-
1
class Ignore < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_docker
-
-
4
builder.call(settings.with(template_path: "%project_name%/.dockerignore.erb")).render
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Documentation
-
# Builds project skeleton citation documentation.
-
1
class Citation < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
else: 5
then: 4
return false unless settings.build_citation
-
-
5
builder.call(settings.with(template_path: "%project_name%/CITATION.cff.erb")).render
-
5
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Documentation
-
# Builds project skeleton LICENSE documentation.
-
1
class License < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
21
else: 17
then: 4
return false unless settings.build_license
-
-
17
settings.with(template_path: "%project_name%/LICENSE-#{license}.#{kind}.erb")
-
.then do |updated_settings|
-
17
builder.call(updated_settings).render.rename "LICENSE.#{kind}"
-
end
-
-
17
true
-
end
-
-
1
private
-
-
1
def kind = settings.documentation_format
-
-
1
def license = settings.license_name
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Documentation
-
# Builds project skeleton README documentation.
-
1
class Readme < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
11
else: 7
then: 4
return false unless settings.build_readme
-
-
7
builder.call(settings.with(template_path: "%project_name%/README.#{kind}.erb"))
-
.render
-
.replace(/\n{2,}/, "\n\n")
-
.replace("\n \n", "\n")
-
-
7
true
-
end
-
-
1
protected
-
-
1
def kind = settings.documentation_format
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
1
require "tocer"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Documentation
-
# Builds project skeleton version history.
-
1
class Version < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
11
else: 7
then: 4
return false unless settings.build_versions
-
-
7
builder.call(settings.with(template_path: "%project_name%/VERSIONS.#{kind}.erb")).render
-
-
7
true
-
end
-
-
1
private
-
-
1
def kind = settings.documentation_format
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Git
-
# Builds project skeleton initial Git commit message.
-
1
class Commit < Abstract
-
1
include Dependencies[:specification]
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_git
-
-
4
builder.call(settings)
-
.run("git add .", chdir: project_name)
-
.run(
-
%(git commit --all --message "Added project skeleton" --message "#{body}"),
-
chdir: project_name
-
)
-
-
4
true
-
end
-
-
1
private
-
-
1
def body
-
4
"Generated with link:#{specification.homepage_url}[#{specification.label}] " \
-
"#{specification.version}."
-
end
-
-
1
def project_name = settings.project_name
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Git
-
# Builds Git repository directory and file ignore configuration.
-
1
class Ignore < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_git
-
-
4
builder.call(settings.with(template_path: "%project_name%/.gitignore.erb"))
-
.render
-
.replace(" ", "")
-
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Git
-
# Initializes project skeleton with Git Safe support.
-
1
class Safe < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_git
-
-
4
builder.call(settings.with(template_path: "%project_name%/.git/safe")).make_path
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Git
-
# Initializes project skeleton as a Git repository.
-
1
class Setup < Abstract
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_git
-
-
4
builder.call(settings).run("git init", chdir: settings.project_name)
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module GitHub
-
# Builds project skeleton GitHub CI template.
-
1
class CI < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
10
else: 6
then: 4
return false unless settings.build_git_hub_ci
-
-
6
builder.call(with_template).render.replace(/\n\n\Z/, "\n")
-
6
true
-
end
-
-
1
private
-
-
1
def with_template
-
6
settings.with template_path: "%project_name%/.github/workflows/ci.yml.erb"
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module GitHub
-
# Builds project skeleton GitHub funding template.
-
1
class Funding < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
13
else: 5
then: 8
return false unless settings.build_git_hub && settings.build_funding
-
-
5
settings.with(template_path: "%project_name%/.github/FUNDING.yml.erb")
-
5
.then { |updated_configuration| builder.call(updated_configuration).render }
-
-
5
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module GitHub
-
# Builds project skeleton GitHub templates.
-
1
class Template < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
13
else: 7
then: 6
return false unless settings.build_git_hub
-
-
7
builder.call(with_issue).render
-
7
builder.call(with_pull_request).render
-
7
builder.call(with_configuration).render
-
7
true
-
end
-
-
1
private
-
-
1
def with_issue
-
7
settings.with template_path: "%project_name%/.github/ISSUE_TEMPLATE/issue.md.erb"
-
end
-
-
1
def with_pull_request
-
7
settings.with template_path: "%project_name%/.github/PULL_REQUEST_TEMPLATE.md.erb"
-
end
-
-
1
def with_configuration
-
7
settings.with template_path: "%project_name%/.github/ISSUE_TEMPLATE/config.yml.erb"
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pathname"
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Initializes building of project by checking for existence first.
-
1
class Init < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
6
builder.call(settings.with(template_path: "%project_name%")).check
-
6
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Rake
-
# Builds project skeleton Rake binstub.
-
1
class Binstub < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
else: 5
then: 4
return false unless settings.build_rake
-
-
5
builder.call(settings.with(template_path: "%project_name%/bin/rake.erb"))
-
.render
-
.permit 0o755
-
-
5
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module Rake
-
# Builds project skeleton Rake file configuration.
-
1
class Configuration < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
13
else: 9
then: 4
return false unless settings.build_rake
-
-
9
builder.call(settings.with(template_path: "%project_name%/Rakefile.erb"))
-
.render
-
.replace(/\[\s+/, "[")
-
.replace(/\s+\]/, "]")
-
.replace(" ", "")
-
.replace("task.options", " task.options")
-
.replace(/\n+(?=require)/, "\n")
-
.replace(/\n{2,}/, "\n\n")
-
-
9
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds project skeleton Reek code quality support.
-
1
class Reek < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_reek
-
-
4
builder.call(settings.with(template_path: "%project_name%/.reek.yml.erb")).render
-
4
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module RSpec
-
# Builds RSpec binstub for project skeleton.
-
1
class Binstub < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
else: 5
then: 4
return false unless settings.build_rspec
-
-
5
builder.call(settings.with(template_path: "%project_name%/bin/rspec.erb"))
-
.render
-
.permit 0o755
-
-
5
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module RSpec
-
# Builds RSpec shared context for temporary directories.
-
1
class Context < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
8
else: 4
then: 4
return false unless settings.build_rspec
-
-
4
template = "%project_name%/spec/support/shared_contexts/temp_dir.rb.erb"
-
4
settings.with(template_path: template)
-
4
.then { |updated_configuration| builder.call updated_configuration }
-
.render
-
.replace(/\n\s+\n\s+/, "\n ")
-
-
4
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
1
module RSpec
-
# Builds RSpec spec helper for project skeleton.
-
1
class Helper < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
18
else: 14
then: 4
return false unless settings.build_rspec
-
-
14
builder.call(settings.with(template_path: "%project_name%/spec/spec_helper.rb.erb"))
-
.render
-
.replace(/\A\n/, "")
-
.replace("\n\n\n", "\n\n")
-
.replace("\n \n", "\n")
-
-
14
true
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds project skeleton setup script.
-
1
class Setup < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
11
else: 7
then: 4
return false unless settings.build_setup
-
-
7
builder.call(settings.with(template_path: "%project_name%/bin/setup.erb"))
-
.render
-
.permit 0o755
-
-
7
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Builders
-
# Builds project skeleton Ruby version file.
-
1
class Version < Abstract
-
1
using Refinements::Struct
-
-
1
def call
-
9
builder.call(settings.with(template_path: "%project_name%/.ruby-version.erb"))
-
.render
-
.append("\n")
-
9
true
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Amazing Print flag.
-
1
class AmazingPrint < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Amazing Print gem."
-
-
1
on "--[no-]amazing_print"
-
-
12
default { Container[:settings].build_amazing_print }
-
-
1
def call(boolean) = settings.build_amazing_print = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Bootsnap flag.
-
1
class Bootsnap < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Bootsnap gem."
-
-
1
on "--[no-]bootsnap"
-
-
12
default { Container[:settings].build_bootsnap }
-
-
1
def call(boolean) = settings.build_bootsnap = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Caliber flag.
-
1
class Caliber < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Caliber gem."
-
-
1
on "--[no-]caliber"
-
-
12
default { Container[:settings].build_caliber }
-
-
1
def call(boolean) = settings.build_caliber = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Circle CI flag.
-
1
class CircleCI < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Circle CI support."
-
-
1
on "--[no-]circle_ci"
-
-
12
default { Container[:settings].build_circle_ci }
-
-
1
def call(boolean) = settings.build_circle_ci = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores citation flag.
-
1
class Citation < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add citation documentation."
-
-
1
on "--[no-]citation"
-
-
12
default { Container[:settings].build_citation }
-
-
1
def call(boolean) = settings.build_citation = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores community flag.
-
1
class Community < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add community documentation."
-
-
1
on "--[no-]community"
-
-
12
default { Container[:settings].build_community }
-
-
1
def call(boolean) = settings.build_community = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores conduct flag.
-
1
class Conduct < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add code of conduct documentation."
-
-
1
on "--[no-]conduct"
-
-
12
default { Container[:settings].build_conduct }
-
-
1
def call(boolean) = settings.build_conduct = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores console flag.
-
1
class Console < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add console script."
-
-
1
on "--[no-]console"
-
-
12
default { Container[:settings].build_console }
-
-
1
def call(boolean) = settings.build_console = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores contributions flag.
-
1
class Contributions < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add contributions documentation."
-
-
1
on "--[no-]contributions"
-
-
12
default { Container[:settings].build_contributions }
-
-
1
def call(boolean) = settings.build_contributions = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Developer Certificate of Origin flag.
-
1
class DCOO < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Developer Certificate of Origin documentation."
-
-
1
on "--[no-]dcoo"
-
-
12
default { Container[:settings].build_dcoo }
-
-
1
def call(boolean) = settings.build_dcoo = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Debug flag.
-
1
class Debug < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Debug gem."
-
-
1
on "--[no-]debug"
-
-
12
default { Container[:settings].build_debug }
-
-
1
def call(boolean) = settings.build_debug = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Development Container flag.
-
1
class DevContainer < Sod::Action
-
1
include Dependencies[:settings, :logger]
-
-
1
description "Add Development Container support."
-
-
1
ancillary "DEPRECATED: Will be removed in Version 9.0.0."
-
-
1
on "--[no-]devcontainer"
-
-
13
default { Container[:settings].build_devcontainer }
-
-
1
def call boolean
-
10
logger.warn { "Dev Container support will be removed in Version 9.0.0." }
-
5
settings.build_devcontainer = boolean
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Docker flag.
-
1
class Docker < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Docker support."
-
-
1
on "--[no-]docker"
-
-
12
default { Container[:settings].build_docker }
-
-
1
def call(boolean) = settings.build_docker = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores funding flag.
-
1
class Funding < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add GitHub funding."
-
-
1
on "--[no-]funding"
-
-
12
default { Container[:settings].build_funding }
-
-
1
def call(boolean) = settings.build_funding = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Git flag.
-
1
class Git < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Git repository."
-
-
1
on "--[no-]git"
-
-
12
default { Container[:settings].build_git }
-
-
1
def call(boolean) = settings.build_git = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores GitHub flag.
-
1
class GitHub < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add GitHub code review and issue templates."
-
-
1
on "--[no-]git_hub"
-
-
12
default { Container[:settings].build_git_hub }
-
-
1
def call(boolean) = settings.build_git_hub = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores GitHub CI flag.
-
1
class GitHubCI < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add GitHub continuous integration support."
-
-
1
on "--[no-]git_hub_ci"
-
-
12
default { Container[:settings].build_git_hub_ci }
-
-
1
def call(boolean) = settings.build_git_hub_ci = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Git Lint flag.
-
1
class GitLint < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Git Lint gem."
-
-
1
on "--[no-]git-lint"
-
-
12
default { Container[:settings].build_git_lint }
-
-
1
def call(boolean) = settings.build_git_lint = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores IRB Kit flag.
-
1
class IRBKit < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add IRB Kit gem."
-
-
1
on "--[no-]irb-kit"
-
-
12
default { Container[:settings].build_irb_kit }
-
-
1
def call(boolean) = settings.build_irb_kit = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores license flag.
-
1
class License < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add license documentation."
-
-
1
on "--[no-]license"
-
-
12
default { Container[:settings].build_license }
-
-
1
def call(boolean) = settings.build_license = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Forces maximum settings.
-
1
class Maximum < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
using ::Refinements::Struct
-
-
1
description "Use maximum configuration."
-
-
1
on "--max"
-
-
11
default { Container[:settings].build_maximum }
-
-
1
def call(*) = settings.with! settings.maximize
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Forces minimum settings.
-
1
class Minimum < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
using ::Refinements::Struct
-
-
1
description "Use minimum configuration."
-
-
1
on "--min"
-
-
11
default { Container[:settings].build_minimum }
-
-
1
def call(*) = settings.with! settings.minimize
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores monads flag.
-
1
class Monads < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Dry Monads gem."
-
-
1
on "--[no-]monads"
-
-
12
default { Container[:settings].build_monads }
-
-
1
def call(boolean) = settings.build_monads = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores project (build) name.
-
1
class Name < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Set project name."
-
-
1
on %w[-n --name], argument: "NAME"
-
-
1
def call(name) = settings.project_name = name
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Rake flag.
-
1
class Rake < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Rake gem."
-
-
1
on "--[no-]rake"
-
-
12
default { Container[:settings].build_rake }
-
-
1
def call(boolean) = settings.build_rake = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores readme flag.
-
1
class Readme < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add readme documentation."
-
-
1
on "--[no-]readme"
-
-
12
default { Container[:settings].build_readme }
-
-
1
def call(boolean) = settings.build_readme = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Reek flag.
-
1
class Reek < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Reek gem."
-
-
1
on "--[no-]reek"
-
-
12
default { Container[:settings].build_reek }
-
-
1
def call(boolean) = settings.build_reek = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Refinements flag.
-
1
class Refinements < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Refinements gem."
-
-
1
on "--[no-]refinements"
-
-
12
default { Container[:settings].build_refinements }
-
-
1
def call(boolean) = settings.build_refinements = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores RSpec flag.
-
1
class RSpec < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add RSpec gem."
-
-
1
on "--[no-]rspec"
-
-
12
default { Container[:settings].build_rspec }
-
-
1
def call(boolean) = settings.build_rspec = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Repl Type Completor flag.
-
1
class RTC < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Repl Type Completor gem."
-
-
1
on "--[no-]rtc"
-
-
12
default { Container[:settings].build_rtc }
-
-
1
def call(boolean) = settings.build_rtc = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores security flag.
-
1
class Security < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add security."
-
-
1
on "--[no-]security"
-
-
12
default { Container[:settings].build_security }
-
-
1
def call(boolean) = settings.build_security = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores setup flag.
-
1
class Setup < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add setup script."
-
-
1
on "--[no-]setup"
-
-
12
default { Container[:settings].build_setup }
-
-
1
def call(boolean) = settings.build_setup = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores SimpleCov flag.
-
1
class SimpleCov < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add SimpleCov gem."
-
-
1
on "--[no-]simple_cov"
-
-
12
default { Container[:settings].build_simple_cov }
-
-
1
def call(boolean) = settings.build_simple_cov = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores versions flag.
-
1
class Versions < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add version history."
-
-
1
on "--[no-]versions"
-
-
12
default { Container[:settings].build_versions }
-
-
1
def call(boolean) = settings.build_versions = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Actions
-
# Stores Zeitwerk flag.
-
1
class Zeitwerk < Sod::Action
-
1
include Dependencies[:settings]
-
-
1
description "Add Zeitwerk gem."
-
-
1
on "--[no-]zeitwerk"
-
-
12
default { Container[:settings].build_zeitwerk }
-
-
1
def call(boolean) = settings.build_zeitwerk = boolean
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/struct"
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
1
module Commands
-
# Stores table of contents root path.
-
1
class Build < Sod::Command
-
1
include Dependencies[:settings, :kernel, :logger]
-
-
# Order is important.
-
BUILDERS = [
-
1
Builders::Init,
-
Builders::Core,
-
Builders::Version,
-
Builders::Documentation::Readme,
-
Builders::Documentation::Citation,
-
Builders::Documentation::License,
-
Builders::Documentation::Version,
-
Builders::Git::Setup,
-
Builders::Git::Ignore,
-
Builders::Git::Safe,
-
Builders::Bundler,
-
Builders::Rake::Binstub,
-
Builders::Rake::Configuration,
-
Builders::Console,
-
Builders::CircleCI,
-
Builders::Setup,
-
Builders::GitHub::Template,
-
Builders::GitHub::Funding,
-
Builders::GitHub::CI,
-
Builders::Reek,
-
Builders::RSpec::Binstub,
-
Builders::RSpec::Context,
-
Builders::RSpec::Helper,
-
Builders::Caliber,
-
Builders::DevContainer::Dockerfile,
-
Builders::DevContainer::Compose,
-
Builders::DevContainer::Configuration,
-
Builders::Docker::Build,
-
Builders::Docker::Console,
-
Builders::Docker::Entrypoint,
-
Builders::Docker::Compose,
-
Builders::Docker::File,
-
Builders::Docker::Ignore,
-
Extensions::Bundler,
-
Extensions::Pragmater,
-
Extensions::Tocer,
-
Extensions::Rubocop,
-
Builders::Git::Commit
-
].freeze
-
-
1
handle "build"
-
-
1
description "Build new project."
-
-
1
on Actions::Name
-
1
on Actions::AmazingPrint
-
1
on Actions::Bootsnap
-
1
on Actions::Caliber
-
1
on Actions::CircleCI
-
1
on Actions::Citation
-
1
on Actions::Community
-
1
on Actions::Conduct
-
1
on Actions::Console
-
1
on Actions::Contributions
-
1
on Actions::DCOO
-
1
on Actions::Debug
-
1
on Actions::DevContainer
-
1
on Actions::Docker
-
1
on Actions::Funding
-
1
on Actions::Git
-
1
on Actions::GitHub
-
1
on Actions::GitHubCI
-
1
on Actions::GitLint
-
1
on Actions::IRBKit
-
1
on Actions::License
-
1
on Actions::Maximum
-
1
on Actions::Minimum
-
1
on Actions::Monads
-
1
on Actions::Rake
-
1
on Actions::Readme
-
1
on Actions::Reek
-
1
on Actions::Refinements
-
1
on Actions::RSpec
-
1
on Actions::RTC
-
1
on Actions::Security
-
1
on Actions::Setup
-
1
on Actions::SimpleCov
-
1
on Actions::Versions
-
1
on Actions::Zeitwerk
-
-
1
def initialize(builders: BUILDERS, **)
-
9
super(**)
-
9
@builders = builders
-
end
-
-
1
def call
-
6
log_info "Building project skeleton: #{settings.project_name}..."
-
160
builders.each { |builder| builder.new(settings:, logger:).call }
-
6
log_info "Project skeleton complete!"
-
end
-
-
1
private
-
-
1
attr_reader :builders
-
-
13
def log_info(message) = logger.info { message }
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "sod"
-
-
1
module Rubysmith
-
1
module CLI
-
# The main Command Line Interface (CLI) object.
-
1
class Shell
-
1
include Dependencies[:defaults_path, :xdg_config, :specification]
-
-
1
def initialize(context: Sod::Context, dsl: Sod, **)
-
7
super(**)
-
7
@context = context
-
7
@dsl = dsl
-
end
-
-
1
def call(...) = cli.call(...)
-
-
1
private
-
-
1
attr_reader :context, :dsl
-
-
1
def cli
-
7
context = build_context
-
-
7
dsl.new :rubysmith, banner: specification.banner do
-
7
on(Sod::Prefabs::Commands::Config, context:)
-
7
on Commands::Build
-
7
on(Sod::Prefabs::Actions::Version, context:)
-
7
on Sod::Prefabs::Actions::Help, self
-
end
-
end
-
-
1
def build_context
-
7
context[defaults_path:, xdg_config:, version_label: specification.labeled_version]
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/schema"
-
1
require "etcher"
-
-
1
Dry::Schema.load_extensions :monads
-
-
1
module Rubysmith
-
1
module Configuration
-
1
Contract = Dry::Schema.Params do
-
1
optional(:author_email).filled :string
-
1
optional(:author_family_name).filled :string
-
1
optional(:author_given_name).filled :string
-
1
required(:author_handle).filled :string
-
1
required(:author_uri).filled :string
-
1
required(:build_amazing_print).filled :bool
-
1
required(:build_bootsnap).filled :bool
-
1
required(:build_caliber).filled :bool
-
1
required(:build_circle_ci).filled :bool
-
1
required(:build_citation).filled :bool
-
1
required(:build_cli).filled :bool
-
1
required(:build_community).filled :bool
-
1
required(:build_conduct).filled :bool
-
1
required(:build_console).filled :bool
-
1
required(:build_contributions).filled :bool
-
1
required(:build_dcoo).filled :bool
-
1
required(:build_debug).filled :bool
-
1
required(:build_devcontainer).filled :bool
-
1
required(:build_docker).filled :bool
-
1
required(:build_funding).filled :bool
-
1
required(:build_git).filled :bool
-
1
required(:build_git_hub).filled :bool
-
1
required(:build_git_hub_ci).filled :bool
-
1
required(:build_git_lint).filled :bool
-
1
required(:build_irb_kit).filled :bool
-
1
required(:build_license).filled :bool
-
1
required(:build_maximum).filled :bool
-
1
required(:build_minimum).filled :bool
-
1
required(:build_monads).filled :bool
-
1
required(:build_rake).filled :bool
-
1
required(:build_readme).filled :bool
-
1
required(:build_reek).filled :bool
-
1
required(:build_refinements).filled :bool
-
1
required(:build_rspec).filled :bool
-
1
required(:build_rtc).filled :bool
-
1
required(:build_security).filled :bool
-
1
required(:build_setup).filled :bool
-
1
required(:build_simple_cov).filled :bool
-
1
required(:build_versions).filled :bool
-
1
required(:build_zeitwerk).filled :bool
-
1
optional(:citation_affiliation).filled :string
-
1
optional(:citation_message).filled :string
-
1
optional(:citation_orcid).filled :string
-
1
required(:documentation_format).filled :string
-
1
required(:gems_uri).filled :string
-
1
required(:loaded_at).filled :time
-
1
required(:license_label).filled :string
-
1
required(:license_name).filled :string
-
1
required(:license_version).filled :string
-
1
optional(:organization_label).filled :string
-
1
required(:organization_uri).filled :string
-
1
optional(:project_name).filled :string
-
1
optional(:project_uri_community).filled :string
-
1
optional(:project_uri_conduct).filled :string
-
1
optional(:project_uri_contributions).filled :string
-
1
optional(:project_uri_dcoo).filled :string
-
1
optional(:project_uri_download).filled :string
-
1
optional(:project_uri_funding).filled :string
-
1
optional(:project_uri_home).filled :string
-
1
optional(:project_uri_issues).filled :string
-
1
optional(:project_uri_license).filled :string
-
1
optional(:project_uri_security).filled :string
-
1
optional(:project_uri_source).filled :string
-
1
optional(:project_uri_versions).filled :string
-
1
required(:project_version).filled :string
-
1
required(:repository_handle).filled :string
-
1
required(:repository_uri).filled :string
-
1
required(:target_root).filled Etcher::Types::Pathname
-
1
optional(:template_path).filled Etcher::Types::Pathname
-
1
required(:template_roots).array Etcher::Types::Pathname
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pathname"
-
1
require "refinements/array"
-
1
require "refinements/string"
-
1
require "refinements/struct"
-
-
1
module Rubysmith
-
1
module Configuration
-
# Defines the common configuration content for use throughout the gem.
-
1
Model = Struct.new(
-
:author_email,
-
:author_family_name,
-
:author_given_name,
-
:author_handle,
-
:author_uri,
-
:build_amazing_print,
-
:build_bootsnap,
-
:build_caliber,
-
:build_circle_ci,
-
:build_citation,
-
:build_cli,
-
:build_community,
-
:build_conduct,
-
:build_console,
-
:build_contributions,
-
:build_dcoo,
-
:build_debug,
-
:build_devcontainer,
-
:build_docker,
-
:build_funding,
-
:build_git,
-
:build_git_hub,
-
:build_git_hub_ci,
-
:build_git_lint,
-
:build_irb_kit,
-
:build_license,
-
:build_maximum,
-
:build_minimum,
-
:build_monads,
-
:build_rake,
-
:build_readme,
-
:build_reek,
-
:build_refinements,
-
:build_rspec,
-
:build_rtc,
-
:build_security,
-
:build_setup,
-
:build_simple_cov,
-
:build_versions,
-
:build_zeitwerk,
-
:citation_affiliation,
-
:citation_message,
-
:citation_orcid,
-
:documentation_format,
-
:gems_uri,
-
:license_label,
-
:license_name,
-
:license_version,
-
:loaded_at,
-
:organization_label,
-
:organization_uri,
-
:project_name,
-
:project_uri_community,
-
:project_uri_conduct,
-
:project_uri_contributions,
-
:project_uri_dcoo,
-
:project_uri_download,
-
:project_uri_funding,
-
:project_uri_home,
-
:project_uri_issues,
-
:project_uri_license,
-
:project_uri_security,
-
:project_uri_source,
-
:project_uri_versions,
-
:project_version,
-
:repository_handle,
-
:repository_uri,
-
:target_root,
-
:template_path,
-
:template_roots
-
) do
-
1
using Refinements::Array
-
1
using Refinements::String
-
1
using Refinements::Struct
-
-
1
def maximize = update_build_options true
-
-
1
def minimize = update_build_options false
-
-
1
def author_name = [author_given_name, author_family_name].compress.join(" ")
-
-
1
def license_label_version = [license_label, license_version].compress.join("-")
-
-
1
def project_class = project_namespaced_class.split("::").last
-
-
1
def project_namespaced_class = project_name.camelcase
-
-
1
def project_label = project_name.titleize
-
-
1
def project_levels = project_namespaced_class.split("::").size - 1
-
-
1
def project_path = project_name.snakecase
-
-
1
def project_root = target_root.join(project_name)
-
-
1
def computed_project_uri_community = format_uri(__method__)
-
-
1
def computed_project_uri_conduct = format_uri(__method__)
-
-
1
def computed_project_uri_contributions = format_uri(__method__)
-
-
1
def computed_project_uri_dcoo = format_uri(__method__)
-
-
1
def computed_project_uri_download = format_uri(__method__)
-
-
1
def computed_project_uri_funding = format_uri(__method__)
-
-
1
def computed_project_uri_home = format_uri(__method__)
-
-
1
def computed_project_uri_issues = format_uri(__method__)
-
-
1
def computed_project_uri_license = format_uri(__method__)
-
-
1
def computed_project_uri_security = format_uri(__method__)
-
-
1
def computed_project_uri_source = format_uri(__method__)
-
-
1
def computed_project_uri_versions = format_uri(__method__)
-
-
1
def ascii_doc? = documentation_format == "adoc"
-
-
1
def markdown? = documentation_format == "md"
-
-
1
def pathway
-
1779
Pathway[start_root: template_root, start_path: template_path, end_root: target_root]
-
end
-
-
1
def template_root
-
1783
Array(template_roots).map(&:expand_path)
-
1784
.find { |path| path.join(String(template_path)).exist? }
-
end
-
-
1
private
-
-
1
def format_uri kind
-
89
kind.to_s
-
.sub("computed_", "")
-
89
.then { |method| public_send method }
-
89
.then { |uri| String uri }
-
89
.then { |uri| uri.sub "%<project_name>s", project_name }
-
end
-
-
1
def update_build_options value
-
13916
to_h.select { |key, _value| key.start_with? "build_" }
-
6860
.transform_values { value }
-
196
.then { |attributes| dup.with!(**attributes, build_minimum: !value) }
-
.freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
-
1
module Rubysmith
-
1
module Configuration
-
1
module Transformers
-
# Dynamically adds Git email if defined.
-
1
class GitEmail
-
1
include Dependencies[:git]
-
1
include Dry::Monads[:result]
-
-
1
def initialize(key = :author_email, **)
-
381
@key = key
-
381
super(**)
-
end
-
-
382
then: 1
else: 380
def call(attributes) = attributes[key] ? Success(attributes) : email_or(attributes)
-
-
1
private
-
-
1
attr_reader :key
-
-
1
def email_or attributes
-
380
git.get("user.email", nil)
-
379
then: 378
else: 1
.fmap { |value| value ? attributes.merge!(key => value) : attributes }
-
1
.or { Success attributes }
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
-
1
module Rubysmith
-
1
module Configuration
-
1
module Transformers
-
# Dynamically updates repository handle if GitHub user is defined.
-
1
class GitHubUser
-
1
include Dependencies[:git]
-
1
include Dry::Monads[:result]
-
-
1
def initialize(key = :repository_handle, **)
-
381
@key = key
-
381
super(**)
-
end
-
-
382
then: 378
else: 3
def call(attributes) = attributes[key] ? Success(attributes) : user_or(attributes)
-
-
1
private
-
-
1
attr_reader :key
-
-
1
def user_or attributes
-
3
git.get("github.user", nil)
-
2
then: 1
else: 1
.fmap { |value| value ? attributes.merge!(key => value) : attributes }
-
1
.or { Success attributes }
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
-
1
module Rubysmith
-
1
module Configuration
-
1
module Transformers
-
# Dynamically adds Git user if defined.
-
1
class GitUser
-
1
include Dependencies[:git]
-
1
include Dry::Monads[:result]
-
-
1
def call attributes
-
383
then: 3
if attributes[:author_given_name] || attributes[:author_family_name]
-
3
Success attributes
-
else: 380
else
-
380
name_or attributes
-
end
-
end
-
-
1
private
-
-
2
def name_or(attributes) = split(attributes).or { Success attributes }
-
-
1
def split attributes
-
380
git.get("user.name", nil).fmap do |name|
-
379
else: 378
then: 1
next attributes unless name
-
-
378
first, last = String(name).split
-
378
attributes.merge! author_given_name: first, author_family_name: last
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
1
require "refinements/array"
-
-
1
module Rubysmith
-
1
module Configuration
-
1
module Transformers
-
# Appends custom path to default template roots.
-
1
class TemplateRoot
-
1
include Dry::Monads[:result]
-
-
1
using Refinements::Array
-
-
1
def initialize key = :template_roots, default: Pathname(__dir__).join("../../templates")
-
383
@key = key
-
383
@default = default
-
end
-
-
1
def call attributes
-
764
Array(default).map { |path| Pathname path }
-
.including(attributes[key])
-
.compact
-
383
.then { |value| Success attributes.merge!(key => value) }
-
end
-
-
1
private
-
-
1
attr_reader :key, :default
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Rubysmith
-
1
Dependencies = Infusible[Container]
-
end
-
# frozen_string_literal: true
-
-
1
require "bundler"
-
1
require "bundler/cli"
-
1
require "refinements/io"
-
1
require "refinements/pathname"
-
-
1
module Rubysmith
-
1
module Extensions
-
# Ensures gem dependencies are installed.
-
1
class Bundler
-
1
include Dependencies[:settings, :logger]
-
-
1
using Refinements::IO
-
1
using Refinements::Pathname
-
-
1
def initialize(client: ::Bundler::CLI, **)
-
10
@client = client
-
10
super(**)
-
end
-
-
1
def call
-
20
logger.info { "Installing gem dependencies..." }
-
10
install
-
rescue ::Bundler::HTTPError
-
2
log_error
-
end
-
-
1
private
-
-
1
attr_reader :client
-
-
1
def install
-
10
settings.project_root.change_dir do
-
10
client.start %w[install --quiet]
-
16
STDOUT.squelch { client.start %w[lock --add-platform x86_64-linux --update] }
-
end
-
-
8
true
-
end
-
-
1
def log_error
-
4
logger.error { "Unable to install gem dependencies. Is your network stable?" }
-
2
false
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pragmater"
-
1
require "refinements/pathname"
-
-
1
module Rubysmith
-
1
module Extensions
-
# Ensures project skeleton has pragmas.
-
1
class Pragmater
-
1
include Dependencies[:settings, :logger]
-
-
1
using Refinements::Pathname
-
-
1
CLIENT = ::Pragmater::Inserter.new(
-
settings: ::Pragmater::Configuration::Model[
-
comments: ["# frozen_string_literal: true"],
-
patterns: %w[
-
**/*.rake
-
**/*.rb
-
*.gemspec
-
exe/*
-
bin/console
-
bin/rake
-
bin/rspec
-
bin/rubocop
-
bin/setup
-
config.ru
-
Gemfile
-
Rakefile
-
]
-
]
-
).freeze
-
-
1
def initialize(client: CLIENT, **)
-
7
@client = client
-
7
super(**)
-
end
-
-
1
def call
-
14
logger.info { "Adding frozen string literal pragmas..." }
-
14
settings.project_root.change_dir { client.call }
-
7
true
-
end
-
-
1
private
-
-
1
attr_reader :client
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/io"
-
1
require "refinements/pathname"
-
1
require "rubocop"
-
-
1
module Rubysmith
-
1
module Extensions
-
# Ensures project skeleton adheres to style guide.
-
1
class Rubocop
-
1
include Dependencies[:settings, :logger]
-
-
1
using Refinements::IO
-
1
using Refinements::Pathname
-
-
1
def initialize(client: ::RuboCop::CLI.new, **)
-
7
@client = client
-
7
super(**)
-
end
-
-
1
def call
-
14
logger.info { "Running RuboCop autocorrect..." }
-
7
autocorrect
-
7
true
-
end
-
-
1
private
-
-
1
attr_reader :client
-
-
1
def autocorrect
-
7
project_root = settings.project_root
-
-
7
project_root.change_dir do
-
14
STDOUT.squelch { client.run ["--autocorrect-all", project_root.to_s] }
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/pathname"
-
1
require "stringio"
-
1
require "tocer"
-
-
1
module Rubysmith
-
1
module Extensions
-
# Ensures project skeleton documentation has table of content.
-
1
class Tocer
-
1
include Dependencies[:settings, :logger]
-
-
1
using Refinements::Pathname
-
-
1
def initialize(client: ::Tocer::Runner.new(io: StringIO.new), **)
-
13
@client = client
-
13
super(**)
-
end
-
-
1
def call
-
13
else: 3
then: 10
return false unless settings.build_readme && settings.markdown?
-
-
6
logger.info { "Adding table of contents..." }
-
3
upsert
-
3
true
-
end
-
-
1
private
-
-
1
attr_reader :client
-
-
4
def upsert = settings.project_root.change_dir { client.call }
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/pathname"
-
-
1
module Rubysmith
-
# Represents a pathway which has source start and destination end.
-
1
Pathway = Struct.new :start_root, :start_path, :end_root, keyword_init: true do
-
1
using Refinements::Pathname
-
-
# :reek:TooManyStatements
-
1
def initialize *arguments
-
1804
super
-
7216
each_pair { |key, value| self[key] = Pathname value }
-
1804
then: 21
else: 1783
self[:start_path] = start_path.absolute? ? start_path : start_root.join(start_path)
-
1804
freeze
-
end
-
-
1
def with(attributes) = self.class.new(to_h.merge(attributes))
-
-
1
def end_path = end_root.join(from_parent, start_path.basename)
-
-
1
def partial? = start_path.basename.fnmatch?("_*")
-
-
1
private
-
-
1
def from_parent
-
1511
then: 16
else: 1495
return end_root.join start_path.parent if start_path.relative?
-
-
1495
start_path.relative_parent start_root
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "erb"
-
-
1
module Rubysmith
-
1
module Renderers
-
# Renders ERB templates as fully functional files.
-
1
class ERB
-
1
def initialize settings,
-
scope: Renderers::Namespace.new(settings.project_namespaced_class),
-
client: ::ERB
-
280
@settings = settings
-
280
@scope = scope
-
280
@client = client
-
end
-
-
1
def call(content) = client.new(content, trim_mode: "<>", eoutvar: "@buffer").result(binding)
-
-
1
private
-
-
1
attr_accessor :buffer
-
1
attr_reader :settings, :scope, :client
-
-
1
def namespace
-
24
source = buffer.dup
-
-
24
then: 12
self.buffer = source + if block_given?
-
12
scope.call yield.sub(source, "")
-
else: 12
else
-
12
scope.call
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/string"
-
-
1
module Rubysmith
-
1
module Renderers
-
# Renders single or multiple modules with correct, two-space indentation for templates.
-
1
class Namespace
-
1
using Refinements::String
-
-
1
def initialize namespace, delimiter: "::"
-
285
@namespace = namespace
-
285
@modules = namespace.split delimiter
-
285
@depth = namespace.scan(delimiter).length
-
end
-
-
1
def call(content = nil) = "#{prefix}#{body content}#{suffix}"
-
-
1
private
-
-
1
attr_reader :namespace, :modules, :depth
-
-
1
def prefix
-
29
modules.each.with_index.reduce "" do |snippet, (module_name, index)|
-
45
%(#{snippet}#{"module".indent index} #{module_name}\n)
-
end
-
end
-
-
# :reek:FeatureEnvy
-
1
def body content
-
29
String(content).lstrip.split("\n").reduce "" do |snippet, line|
-
57
then: 11
else: 46
next "#{snippet}\n" if line.blank?
-
-
46
"#{snippet}#{line.gsub(/^\s{2}/, "").indent depth + 1}\n"
-
end
-
end
-
-
1
def suffix
-
29
modules.each.with_index.reduce "" do |snippet, (_, index)|
-
45
%(#{snippet}#{"end".indent depth - index}\n)
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Rubysmith
-
1
module Text
-
# Inserts content before or after a line for a given pattern in an array of lines.
-
1
class Inserter
-
1
def initialize lines, kind = :after
-
55
@lines = lines.dup
-
55
@kind = kind
-
end
-
-
1
def call content, pattern
-
242
lines.index { |line| line.match? pattern }
-
54
then: 52
else: 2
.then { |index| lines.insert index + offset, content if index }
-
53
lines
-
end
-
-
1
private
-
-
1
attr_reader :lines, :kind
-
-
1
def offset
-
52
when: 21
case kind
-
21
when: 30
when :before then 0
-
30
else: 1
when :after then 1
-
1
else fail StandardError, "Unknown kind of insert: #{kind}."
-
end
-
end
-
end
-
end
-
end