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

Defined Under Namespace

Classes: NotAllowedInEnvError

Instance Method Summary collapse

Constructor Details

#initialize(config, args) ⇒ Action

Returns a new instance of Action.



10
11
12
13
# File 'lib/action.rb', line 10

def initialize(config, args)
	@config = config
	@args = args
end

Instance Method Details

#aliasObject



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

def alias
	@config["alias"]
end

#commandObject



31
32
33
# File 'lib/action.rb', line 31

def command
	@config["command"]
end

#config_errorsObject



47
48
49
50
51
52
53
54
55
# File 'lib/action.rb', line 47

def config_errors
	@config_errors ||= begin
		errors = []

		errors << "No 'command' specified in 'action'." unless @config['command']

		errors
	end
end

#config_valid?Boolean

Returns:

  • (Boolean)


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

def config_valid?
	config_errors.empty?
end

#descriptionObject



35
36
37
# File 'lib/action.rb', line 35

def description
	@config["description"]
end

#load_secrets?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/action.rb', line 57

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

#runObject



15
16
17
18
19
20
21
# File 'lib/action.rb', line 15

def run
	unless allowed_in_current_env?
		raise NotAllowedInEnvError, "Action not allowed in #{Environment.environment} environment."
	end

	Kernel.exec(to_s)
end

#skip_hooks?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



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

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