Class: Action
- Inherits:
-
Object
- Object
- Action
- Defined in:
- lib/action.rb
Overview
represents one action to be performed in the shell can assemble a command line from a command and args
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #alias ⇒ Object
- #aliases ⇒ Object
- #allowed_in_env?(env) ⇒ Boolean
- #command ⇒ Object
- #config_errors ⇒ Object
- #config_valid? ⇒ Boolean
- #description ⇒ Object
- #execute_in_env?(env) ⇒ Boolean
-
#initialize(name, config, args) ⇒ Action
constructor
A new instance of Action.
- #load_secrets? ⇒ Boolean
- #run ⇒ Object
- #skip_hooks?(name) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(name, config, args) ⇒ Action
Returns a new instance of Action.
8 9 10 11 12 |
# File 'lib/action.rb', line 8 def initialize(name, config, args) @name = name @config = config || {} @args = args end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/action.rb', line 6 def name @name end |
Instance Method Details
#alias ⇒ Object
28 29 30 |
# File 'lib/action.rb', line 28 def alias @config["alias"] || @config["aliases"]&.first end |
#aliases ⇒ Object
32 33 34 35 36 |
# File 'lib/action.rb', line 32 def aliases return [@config["alias"]].compact unless @config["aliases"] ([@config["alias"]] + @config["aliases"]).compact end |
#allowed_in_env?(env) ⇒ Boolean
74 75 76 77 78 79 80 |
# File 'lib/action.rb', line 74 def allowed_in_env?(env) return false if not_in_envs.include?(env) return false if in_envs.any? && !in_envs.include?(env) true end |
#command ⇒ Object
38 39 40 41 42 |
# File 'lib/action.rb', line 38 def command return @config if @config.is_a?(String) @config["command"] end |
#config_errors ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/action.rb', line 56 def config_errors @config_errors ||= begin errors = [] errors << "No 'command' specified in 'action'." unless command errors end end |
#config_valid? ⇒ Boolean
52 53 54 |
# File 'lib/action.rb', line 52 def config_valid? config_errors.empty? end |
#description ⇒ Object
44 45 46 |
# File 'lib/action.rb', line 44 def description @config["description"] end |
#execute_in_env?(env) ⇒ Boolean
70 71 72 |
# File 'lib/action.rb', line 70 def execute_in_env?(env) !skip_in_envs.include?(env) end |
#load_secrets? ⇒ Boolean
66 67 68 |
# File 'lib/action.rb', line 66 def load_secrets? @config["load_secrets"].nil? ? false : @config["load_secrets"] end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/action.rb', line 14 def run Output.error(Profiler.summary) if Profiler.summary if perform_shell_expansion? Kernel.exec(to_s) else Kernel.exec(*to_a) end end |
#skip_hooks?(name) ⇒ Boolean
48 49 50 |
# File 'lib/action.rb', line 48 def skip_hooks?(name) @config["skip_#{name}_hooks"] end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/action.rb', line 24 def to_s "#{command} #{@args.join(' ')}".strip end |