Class: Mammoth::Commands::DeliverSampleCommand
- Inherits:
-
Object
- Object
- Mammoth::Commands::DeliverSampleCommand
- Defined in:
- lib/mammoth/commands/deliver_sample_command.rb
Overview
Delivers one JSON event file through the configured local application.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#event_path ⇒ Object
readonly
Returns the value of attribute event_path.
-
#lifecycle_hooks ⇒ Object
readonly
Returns the value of attribute lifecycle_hooks.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#call ⇒ Integer
Process-style status code.
-
#initialize(config, event_path:, output: $stdout, lifecycle_hooks: LifecycleHooks.new) ⇒ DeliverSampleCommand
constructor
A new instance of DeliverSampleCommand.
Constructor Details
#initialize(config, event_path:, output: $stdout, lifecycle_hooks: LifecycleHooks.new) ⇒ DeliverSampleCommand
Returns a new instance of DeliverSampleCommand.
15 16 17 18 19 20 |
# File 'lib/mammoth/commands/deliver_sample_command.rb', line 15 def initialize(config, event_path:, output: $stdout, lifecycle_hooks: LifecycleHooks.new) @config = config @event_path = event_path @output = output @lifecycle_hooks = lifecycle_hooks end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/mammoth/commands/deliver_sample_command.rb', line 9 def config @config end |
#event_path ⇒ Object (readonly)
Returns the value of attribute event_path.
9 10 11 |
# File 'lib/mammoth/commands/deliver_sample_command.rb', line 9 def event_path @event_path end |
#lifecycle_hooks ⇒ Object (readonly)
Returns the value of attribute lifecycle_hooks.
9 10 11 |
# File 'lib/mammoth/commands/deliver_sample_command.rb', line 9 def lifecycle_hooks @lifecycle_hooks end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
9 10 11 |
# File 'lib/mammoth/commands/deliver_sample_command.rb', line 9 def output @output end |
Instance Method Details
#call ⇒ Integer
Returns process-style status code.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mammoth/commands/deliver_sample_command.rb', line 23 def call raise ConfigurationError, "event JSON file not found: #{event_path}" unless File.file?(event_path) event = JSON.parse(File.read(event_path)) processed = Application.new(config, source: [event], lifecycle_hooks: lifecycle_hooks).start output.puts "Processed sample events: #{processed}" 0 rescue JSON::ParserError => e raise ConfigurationError, "invalid event JSON in #{event_path}: #{e.}" end |