Module: Asgard::Base::TaskDSL
- Included in:
- Asgard::Base
- Defined in:
- lib/asgard/base/task_dsl.rb
Overview
Task-definition macros available inside .loki files: single-argument
desc, --no-x/--skip-x suppression, .env loading, the helper
DSL, and default_task override warnings.
Instance Method Summary collapse
- #default_task(meth = nil) ⇒ Object
-
#desc(usage_or_desc, description = nil, options = {}) ⇒ Object
Allow single-argument desc: desc "Run the tests" The usage string defaults to the method name when the description is the only arg.
- #dotenv(path = ".env") ⇒ Object
- #helper(name) ⇒ Object
-
#no_negate(*names) ⇒ Object
Suppress [--no-name] / [--skip-name] from help for boolean class options where negation is meaningless.
Instance Method Details
#default_task(meth = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/asgard/base/task_dsl.rb', line 46 def default_task(meth = nil) active = meth && meth != :none here = caller_locations(1, 1).first if active if active && @_default_task_location # rubocop:disable-next Style/StderrPuts -- warn bypasses $stderr in Ruby 4.0, breaking capture_io in tests $stderr.puts "asgard: default_task :#{meth} at #{here.path}:#{here.lineno} " \ "overrides default_task :#{@_default_task_name} set at " \ "#{@_default_task_location.path}:#{@_default_task_location.lineno}" end if active @_default_task_location = here @_default_task_name = meth end super end |
#desc(usage_or_desc, description = nil, options = {}) ⇒ Object
Allow single-argument desc: desc "Run the tests" The usage string defaults to the method name when the description is the only arg.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/asgard/base/task_dsl.rb', line 11 def desc(usage_or_desc, description = nil, = {}) is_hash = description.is_a?(Hash) if description.nil? || is_hash = description if is_hash @_pending_single_desc = usage_or_desc @_pending_single_desc_opts = else @_pending_single_desc = nil @_pending_single_desc_opts = nil super end end |
#dotenv(path = ".env") ⇒ Object
36 37 38 39 |
# File 'lib/asgard/base/task_dsl.rb', line 36 def dotenv(path = ".env") require "dotenv" Dotenv.load(path) if File.exist?(path) end |
#helper(name) ⇒ Object
41 42 43 44 |
# File 'lib/asgard/base/task_dsl.rb', line 41 def helper(name, &) define_singleton_method(name, &) no_commands { private define_method(name) { |*args, **kwargs, &blk| self.class.send(name, *args, **kwargs, &blk) } } end |
#no_negate(*names) ⇒ Object
Suppress [--no-name] / [--skip-name] from help for boolean class options where negation is meaningless. Call after class_option declarations.
26 27 28 29 30 31 32 33 34 |
# File 'lib/asgard/base/task_dsl.rb', line 26 def no_negate(*names) names.each do |name| opt = [name] next unless opt opt.define_singleton_method(:usage) do |padding = 0| aliases_for_usage.ljust(padding) + "[#{switch_name}]" end end end |