class Toys::Templates::Rake
A template that generates tools matching a rakefile.
Constants
- DEFAULT_RAKEFILE_PATH
Default path to the Rakefile. @return [String]
Attributes
Set the bundler state and options for all Rake
tools.
Pass `false` to disable bundler. Pass `true` or a hash of options to enable bundler. See the documentation for the [bundler mixin](dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler) for information on the options that can be passed.
@param value [Boolean,Hash] @return [Boolean,Hash]
Custom context directory for this tool.
@param value [String] @return [String]
Version requirements for the minitest gem. If set to `nil`, has no version requirement (unless one is specified in the bundle.)
@param value [String,Array<String>,nil] @return [String,Array<String>,nil]
Whether to generate tools only for rake tasks with descriptions.
@param value [Boolean] @return [Boolean]
Path to the Rakefile. If set to `nil`, defaults to {DEFAULT_RAKEFILE_PATH}.
@param value [String,nil] @return [String,nil]
Whether generated tools should use flags instead of positional arguments to pass arguments to rake tasks.
@param value [Boolean] @return [Boolean]
Public Class Methods
@private
# File lib/toys/templates/rake.rb, line 207 def self.find_rakefile(path, context_dir) if path == ::File.absolute_path(path) return ::File.file?(path) && ::File.readable?(path) ? path : nil end dir = ::Dir.getwd 50.times do rakefile_path = ::File.expand_path(path, dir) return rakefile_path if ::File.file?(rakefile_path) && ::File.readable?(rakefile_path) break if dir == context_dir next_dir = ::File.dirname(dir) break if dir == next_dir dir = next_dir end nil end
@private
# File lib/toys/templates/rake.rb, line 195 def self.flag_specs(arg) name = arg.to_s.gsub(/\W/, "").downcase specs = [] unless name.empty? specs << "--#{name}=VALUE" name2 = name.tr("_", "-") specs << "--#{name2}=VALUE" unless name2 == name end specs end
Create the template settings for the rake template.
@param gem_version
[String,Array<String>,nil] Version requirements for
the rake gem. Defaults to nil, indicating no version requirement.
@param rakefile_path
[String] Path to the Rakefile. Defaults to
{DEFAULT_RAKEFILE_PATH}.
@param only_described
[Boolean] If true, tools are generated only for
rake tasks with descriptions. Default is false.
@param use_flags
[Boolean] Generated tools use flags instead of
positional arguments to pass arguments to rake tasks. Default is false.
@param bundler [Boolean,Hash] If `false` (the default), bundler is not
enabled for Rake tools. If `true` or a Hash of options, bundler is enabled. See the documentation for the [bundler mixin](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler) for information on available options.
@param context_directory
[String] A custom context directory to use
when executing this tool.
# File lib/toys/templates/rake.rb, line 37 def initialize(gem_version: nil, rakefile_path: nil, only_described: false, use_flags: false, bundler: false, context_directory: nil) @gem_version = gem_version @rakefile_path = rakefile_path @only_described = only_described @use_flags = use_flags @bundler = bundler @context_directory = context_directory end
@private
# File lib/toys/templates/rake.rb, line 224 def self.prepare_rake(rakefile_path, context_dir) ::Rake::TaskManager.record_task_metadata = true rake = ::Rake::Application.new ::Rake.application = rake ::Dir.chdir(context_dir) do ::Rake.load_rakefile(rakefile_path) end rake end
Public Instance Methods
@private
# File lib/toys/templates/rake.rb, line 141 def bundler_settings if @bundler && !@bundler.is_a?(::Hash) {} else @bundler end end
@private
# File lib/toys/templates/rake.rb, line 131 def gem_version Array(@gem_version) end
@private
# File lib/toys/templates/rake.rb, line 136 def rakefile_path @rakefile_path || DEFAULT_RAKEFILE_PATH end
Use bundler for all Rake
tools.
See the documentation for the [bundler mixin](dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler) for information on the options that can be passed.
@param opts [keywords] Options for bundler @return [self]
# File lib/toys/templates/rake.rb, line 118 def use_bundler(**opts) @bundler = opts self end