Class: Console::Event::Spawn
- Defined in:
- lib/console/event/spawn.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #chdir_string(options) ⇒ Object
- #format(output, terminal, verbose) ⇒ Object
-
#initialize(environment, arguments, options) ⇒ Spawn
constructor
A new instance of Spawn.
- #to_h ⇒ Object
Methods inherited from Generic
Constructor Details
#initialize(environment, arguments, options) ⇒ Spawn
Returns a new instance of Spawn.
21 22 23 24 25 |
# File 'lib/console/event/spawn.rb', line 21 def initialize(environment, arguments, ) @environment = environment @arguments = arguments @options = end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
28 29 30 |
# File 'lib/console/event/spawn.rb', line 28 def arguments @arguments end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
27 28 29 |
# File 'lib/console/event/spawn.rb', line 27 def environment @environment end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
29 30 31 |
# File 'lib/console/event/spawn.rb', line 29 def @options end |
Class Method Details
.for(*arguments, **options) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/console/event/spawn.rb', line 11 def self.for(*arguments, **) # Extract out the command environment: if arguments.first.is_a?(Hash) environment = arguments.shift self.new(environment, arguments, ) else self.new(nil, arguments, ) end end |
.register(terminal) ⇒ Object
37 38 39 |
# File 'lib/console/event/spawn.rb', line 37 def self.register(terminal) terminal[:shell_command] ||= terminal.style(:blue, nil, :bold) end |
Instance Method Details
#chdir_string(options) ⇒ Object
31 32 33 34 35 |
# File 'lib/console/event/spawn.rb', line 31 def chdir_string() if and chdir = [:chdir] " in #{chdir}" end end |
#format(output, terminal, verbose) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/console/event/spawn.rb', line 49 def format(output, terminal, verbose) arguments = @arguments.flatten.collect(&:to_s) output.puts " #{terminal[:shell_command]}#{arguments.join(' ')}#{terminal.reset}#{chdir_string()}" if verbose and @environment @environment.each do |key, value| output.puts " export #{key}=#{value}" end end end |
#to_h ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/console/event/spawn.rb', line 41 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 |