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



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

def alias
	@config["alias"]
end

#commandObject



33
34
35
# File 'lib/action.rb', line 33

def command
	@config["command"]
end

#config_errorsObject



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

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

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

		errors
	end
end

#config_valid?Boolean

Returns:

  • (Boolean)


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

def config_valid?
	config_errors.empty?
end

#descriptionObject



37
38
39
# File 'lib/action.rb', line 37

def description
	@config["description"]
end

#runObject



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

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

	Secrets.load if load_secrets?

	Kernel.exec(to_s)
end

#skip_hooks?(name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/action.rb', line 41

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

#to_sObject



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

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