Sha256: 3f68a4035d3874563df90e0bc617d4a7e504b76be6bab04cb0d16ad6ec48c0d4

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, "list", when given the `channel`
      # option.
      #
      class Pending
        include Messaging

        attr_reader :client, :channel

        def initialize(client, channel = nil)
          @client  = client
          @channel = channel
        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 for channel `#{channel}`:"
            events.each { |event| info(event.to_json) }
          else
            info "No pending events found for channel `#{channel}`"
          end
        end

        def events
          return @events if @events
          response = client.pending(channel)
          @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/pending.rb
search-kit-0.0.1 lib/search_kit/events/cli/pending.rb