class Runfile::Action
Represents a single action inside a {Userfile} and executes its block on demand. Properties of this class are populated by the {DSL} module when the runfile is executed.
Attributes
block[RW]
help[RW]
host[RW]
name[R]
shortcut[R]
Public Instance Methods
command_string()
click to toggle source
# File lib/runfile/action.rb, line 11 def command_string result = names.join(', ') result.empty? ? '(default)' : result end
implicit_usages()
click to toggle source
# File lib/runfile/action.rb, line 16 def implicit_usages usages.empty? ? [usage_string] : usages end
inspectable()
click to toggle source
# File lib/runfile/action.rb, line 20 def inspectable { name: name, prefix: prefix, 'host.path': host&.path } end
name=(value)
click to toggle source
# File lib/runfile/action.rb, line 33 def name=(value) @name = value&.to_s end
prefix()
click to toggle source
# File lib/runfile/action.rb, line 37 def prefix host&.full_name end
run(args = {})
click to toggle source
# File lib/runfile/action.rb, line 24 def run(args = {}) validate_context instance_eval do host.helpers.each { |b| b.call args } block.call args if block end end
shortcut=(value)
click to toggle source
# File lib/runfile/action.rb, line 41 def shortcut=(value) @shortcut = value&.to_s end
usage_string()
click to toggle source
# File lib/runfile/action.rb, line 45 def usage_string @usage_string ||= if shortcut "#{prefix} (#{name} | #{shortcut})".strip else "#{prefix} #{name}".strip end end
usages()
click to toggle source
# File lib/runfile/action.rb, line 53 def usages @usages ||= [] end
Private Instance Methods
names()
click to toggle source
# File lib/runfile/action.rb, line 59 def names name.empty? ? [] : [name, shortcut].compact end
validate_context()
click to toggle source
# File lib/runfile/action.rb, line 63 def validate_context host.required_contexts.each do |varname, default| next if host.context[varname] raise UserError, "Need #{varname}" if default.nil? host.context[varname] = default end end