Class: Action

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/action.rb', line 6

def name
  @name
end

Instance Method Details

#aliasObject



28
29
30
# File 'lib/action.rb', line 28

def alias
	@config["alias"] || @config["aliases"]&.first
end

#aliasesObject



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

Returns:

  • (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

#commandObject



38
39
40
41
42
# File 'lib/action.rb', line 38

def command
	return @config if @config.is_a?(String)

	@config["command"]
end

#config_errorsObject



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

Returns:

  • (Boolean)


52
53
54
# File 'lib/action.rb', line 52

def config_valid?
	config_errors.empty?
end

#descriptionObject



44
45
46
# File 'lib/action.rb', line 44

def description
	@config["description"]
end

#execute_in_env?(env) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/action.rb', line 70

def execute_in_env?(env)
	!skip_in_envs.include?(env)
end

#load_secrets?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/action.rb', line 66

def load_secrets?
	@config["load_secrets"].nil? ? false : @config["load_secrets"]
end

#runObject



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

Returns:

  • (Boolean)


48
49
50
# File 'lib/action.rb', line 48

def skip_hooks?(name)
	@config["skip_#{name}_hooks"]
end

#to_sObject



24
25
26
# File 'lib/action.rb', line 24

def to_s
	"#{command} #{@args.join(' ')}".strip
end