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



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

def alias
  @config["alias"]
end

#commandObject



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

def command
  @config["command"]
end

#config_errorsObject



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

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

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

    errors
  end
end

#config_valid?Boolean

Returns:

  • (Boolean)


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

def config_valid?
  config_errors.empty?
end

#descriptionObject



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

def description
  @config["description"]
end

#load_secrets?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/action.rb', line 61

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

#runObject



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

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

  if perform_shell_expansion?
    Kernel.exec(to_s)
  else
    Kernel.exec(*to_a)
  end
end

#skip_hooks?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



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

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