Sha256: 245f350fe8ac8f290f16781df7875ae7cfdd033fb82224cb04d27dc3767ddb9a

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

require 'thor'

module SearchKit
  class Events
    class CLI < Thor
      # An extraction of the CLI command, "pending".  When the pending comand
      # is not given any parameters, it looks for all pending events despite
      # of channel - or in other words, the index of events.
      #
      class List
        include Messaging

        attr_reader :client

        def initialize(client)
          @client = client
        end

        def perform
          report_events
        rescue Faraday::ConnectionFailed
          warning "Remote events service not found"
        rescue JSON::ParserError => error
          warning "Response unreadable: #{error}"
          error.backtrace.each(&method(:warning))
        end

        private

        def report_events
          if events.any?
            info "Pending events:"
            events.each { |event| info(event.to_json) }
          else
            info "No pending events found"
          end
        end

        def events
          return @events if @events
          response = client.index
          @events = response.fetch(:data, [])
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
search-kit-0.0.2 lib/search_kit/events/cli/list.rb
search-kit-0.0.1 lib/search_kit/events/cli/list.rb