Class: Mammoth::Commands::DeliverSampleCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/commands/deliver_sample_command.rb

Overview

Delivers one JSON event file through the configured local application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, event_path:, output: $stdout, lifecycle_hooks: LifecycleHooks.new) ⇒ DeliverSampleCommand

Returns a new instance of DeliverSampleCommand.

Parameters:

  • config (Mammoth::Configuration)

    loaded configuration

  • event_path (String)

    event JSON path

  • output (#puts) (defaults to: $stdout)

    output stream

  • lifecycle_hooks (Mammoth::LifecycleHooks, Hash) (defaults to: LifecycleHooks.new)

    local lifecycle callbacks



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

#configObject (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_pathObject (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_hooksObject (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

#outputObject (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

#callInteger

Returns process-style status code.

Returns:

  • (Integer)

    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.message}"
end