class Gemsmith::CLI
The Command Line Interface (CLI
) for the gem. rubocop:disable Metrics/ClassLength
Attributes
configuration[R]
Public Class Methods
configuration()
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/gemsmith/cli.rb, line 32 def self.configuration repository = GitPlus::Repository.new Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: { year: Time.now.year, github_user: repository.config_get("github.user"), gem: { label: "Undefined", name: "undefined", path: "undefined", class: "Undefined", platform: "Gem::Platform::RUBY", url: "", license: "MIT" }, author: { name: repository.config_get("user.name"), email: repository.config_get("user.email"), url: "" }, organization: { name: "", url: "" }, versions: { ruby: RUBY_VERSION, rails: "6.1" }, generate: { bundler_audit: true, circle_ci: false, cli: false, git_lint: true, git_hub: false, guard: true, pry: true, engine: false, reek: true, rspec: true, rubocop: true, simple_cov: true, security: false }, publish: { sign: false } } end
generators()
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/gemsmith/cli.rb, line 84 def self.generators [ Generators::Gem, Generators::Documentation, Generators::Rake, Generators::CLI, Generators::Ruby, Generators::Engine, Generators::Rspec, Generators::BundlerAudit, Generators::GitLint, Generators::Reek, Generators::Guard, Generators::CircleCI, Generators::Bundler, Generators::GitHub, Generators::Pragma, Generators::Rubocop, Generators::Git ] end
new(args = [], options = {})
click to toggle source
Initialize.
Calls superclass method
# File lib/gemsmith/cli.rb, line 108 def initialize args = [], options = {}, config = {} super args, options, config @configuration = self.class.configuration rescue Runcom::Errors::Base => error abort error.message end
source_root()
click to toggle source
Overwrites Thor's template source root.
# File lib/gemsmith/cli.rb, line 27 def self.source_root Pathname(__dir__).join("templates").freeze end
Public Instance Methods
config()
click to toggle source
# File lib/gemsmith/cli.rb, line 205 def config path = configuration.current if options.edit? then `#{ENV["EDITOR"]} #{path}` elsif options.info? path ? say(path) : say("Configuration doesn't exist.") else help :config end end
generate(name)
click to toggle source
:reek: TooManyStatements
# File lib/gemsmith/cli.rb, line 170 def generate name print_cli_and_rails_engine_option_error && return if options.cli? && options.engine? say_status :info, "Generating gem...", :green setup_configuration name: name, options: options.to_h self.class.generators.each { |generator| generator.run self, configuration: configuration } say_status :info, "Gem generation finished.", :green end
help(task = nil)
click to toggle source
Calls superclass method
# File lib/gemsmith/cli.rb, line 223 def help task = nil say and super end
open(name)
click to toggle source
# File lib/gemsmith/cli.rb, line 183 def open name process_gem name, "edit" end
read(name)
click to toggle source
# File lib/gemsmith/cli.rb, line 189 def read name say_status :error, "Gem home page is not defined.", :red unless process_gem name, "visit" end
version()
click to toggle source
# File lib/gemsmith/cli.rb, line 217 def version say Identity::VERSION_LABEL end
Private Instance Methods
print_cli_and_rails_engine_option_error()
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/gemsmith/cli.rb, line 251 def print_cli_and_rails_engine_option_error say_status :error, "Generating a gem with CLI and Rails Engine functionality is not allowed. " \ "Build separate gems for improved separation of concerns and design.", :red end
setup_configuration(name:, options: {})
click to toggle source
:reek: FeatureEnvy rubocop:disable Metrics/MethodLength
# File lib/gemsmith/cli.rb, line 233 def setup_configuration name:, options: {} repository = GitPlus::Repository.new @configuration = configuration.to_h.merge( gem: { label: name.titleize, name: name, path: name.snakecase, class: name.camelcase, platform: "Gem::Platform::RUBY", url: %(https://github.com/#{repository.config_get "github.user"}/#{name}), license: "MIT" }, generate: options.symbolize_keys ) end