Class: Console::Event::Spawn
- Defined in:
- lib/console/event/spawn.rb
Overview
Represents a child process spawn event.
“‘ruby Console.info(self, **Console::Event::Spawn.for(“ls”, “-l”))
event = Console::Event::Spawn.for(“ls”, “-l”) event.status = Process.wait “‘
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#status ⇒ Object
Returns the value of attribute status.
- #The end time of the command.(end) ⇒ Object readonly
- #The start time of the command.(starttimeofthecommand.) ⇒ Object readonly
- #The status of the command, if it has completed.(statusofthecommand) ⇒ Object readonly
Class Method Summary collapse
-
.for(*arguments, **options) ⇒ Object
Create a new spawn event.
Instance Method Summary collapse
-
#duration ⇒ Object
Calculate the duration of the command, if it has completed.
-
#emit(*arguments, **options) ⇒ Object
Log the spawn event.
-
#initialize(environment, arguments, options) ⇒ Spawn
constructor
Create a new spawn event.
-
#to_hash ⇒ Object
Convert the spawn event to a hash suitable for JSON serialization.
Methods inherited from Generic
Constructor Details
#initialize(environment, arguments, options) ⇒ Spawn
Create a new spawn event.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/console/event/spawn.rb', line 40 def initialize(environment, arguments, ) @environment = environment @arguments = arguments @options = @start_time = Clock.now @end_time = nil @status = nil end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
55 56 57 |
# File 'lib/console/event/spawn.rb', line 55 def end_time @end_time end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
52 53 54 |
# File 'lib/console/event/spawn.rb', line 52 def start_time @start_time end |
#status ⇒ Object
Returns the value of attribute status.
58 59 60 |
# File 'lib/console/event/spawn.rb', line 58 def status @status end |
#The end time of the command.(end) ⇒ Object (readonly)
55 |
# File 'lib/console/event/spawn.rb', line 55 attr :end_time |
#The start time of the command.(starttimeofthecommand.) ⇒ Object (readonly)
52 |
# File 'lib/console/event/spawn.rb', line 52 attr :start_time |
#The status of the command, if it has completed.(statusofthecommand) ⇒ Object (readonly)
58 |
# File 'lib/console/event/spawn.rb', line 58 attr :status |
Class Method Details
.for(*arguments, **options) ⇒ Object
Create a new spawn event.
25 26 27 28 29 30 31 32 33 |
# File 'lib/console/event/spawn.rb', line 25 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 |
Instance Method Details
#duration ⇒ Object
Calculate the duration of the command, if it has completed.
71 72 73 74 75 |
# File 'lib/console/event/spawn.rb', line 71 def duration if @end_time @end_time - @start_time end end |
#emit(*arguments, **options) ⇒ Object
Log the spawn event.
99 100 101 102 |
# File 'lib/console/event/spawn.rb', line 99 def emit(*arguments, **) [:severity] ||= :info super end |
#to_hash ⇒ Object
Convert the spawn event to a hash suitable for JSON serialization.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/console/event/spawn.rb', line 80 def to_hash Hash.new.tap do |hash| hash[:type] = :spawn hash[:environment] = @environment if @environment&.any? hash[:arguments] = @arguments if @arguments&.any? hash[:options] = @options if @options&.any? hash[:status] = @status.to_i if @status if duration = self.duration hash[:duration] = duration end end end |