Class: Console::Event::Spawn

Inherits:
Generic
  • Object
show all
Defined in:
lib/console/event/spawn.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#to_json

Constructor Details

#initialize(environment, arguments, options) ⇒ Spawn

Returns a new instance of Spawn.



38
39
40
41
42
# File 'lib/console/event/spawn.rb', line 38

def initialize(environment, arguments, options)
	@environment = environment
	@arguments = arguments
	@options = options
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



45
46
47
# File 'lib/console/event/spawn.rb', line 45

def arguments
  @arguments
end

#environmentObject (readonly)

Returns the value of attribute environment.



44
45
46
# File 'lib/console/event/spawn.rb', line 44

def environment
  @environment
end

#optionsObject (readonly)

Returns the value of attribute options.



46
47
48
# File 'lib/console/event/spawn.rb', line 46

def options
  @options
end

Class Method Details

.for(*arguments, **options) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/console/event/spawn.rb', line 28

def self.for(*arguments, **options)
	# Extract out the command environment:
	if arguments.first.is_a?(Hash)
		environment = arguments.shift
		self.new(environment, arguments, options)
	else
		self.new(nil, arguments, options)
	end
end

.register(terminal) ⇒ Object



54
55
56
# File 'lib/console/event/spawn.rb', line 54

def self.register(terminal)
	terminal[:shell_command] ||= terminal.style(:blue, nil, :bold)
end

Instance Method Details

#chdir_string(options) ⇒ Object



48
49
50
51
52
# File 'lib/console/event/spawn.rb', line 48

def chdir_string(options)
	if options and chdir = options[:chdir]
		" in #{chdir}"
	end
end

#format(output, terminal, verbose) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/console/event/spawn.rb', line 66

def format(output, terminal, verbose)
	arguments = @arguments.flatten.collect(&:to_s)
	
	output.puts "  #{terminal[:shell_command]}#{arguments.join(' ')}#{terminal.reset}#{chdir_string(options)}"
	
	if verbose and @environment
		@environment.each do |key, value|
			output.puts "    export #{key}=#{value}"
		end
	end
end

#to_hObject



58
59
60
61
62
63
64
# File 'lib/console/event/spawn.rb', line 58

def to_h
	Hash.new.tap do |hash|
		hash[:environment] = @environment if @environment&.any?
		hash[:arguments] = @arguments if @arguments&.any?
		hash[:options] = @options if @options&.any?
	end
end