Sha256: 54f8227ae71929069975e31a90adf3bf7a883a4458352aa6145d3fcf47381296

Contents?: true

Size: 1.95 KB

Versions: 18

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

module Pennyworth
  # Processes all steps required to render an Alfred Script Filter response.
  class Processor
    def self.for_encodings
      new loader: Loaders::Encodings.new,
          presenter: Presenters::Encoding,
          serializer: Serializers::Encoding
    end

    def self.for_gems
      new loader: Loaders::Projects.for_ruby_gems,
          presenter: Presenters::Gem,
          serializer: Serializers::Project
    end

    def self.for_http_statuses
      new loader: Loaders::HTTPStatuses.new,
          presenter: Presenters::HTTPStatus,
          serializer: Serializers::HTTPStatus
    end

    def self.for_projects
      new loader: Loaders::Projects.for_git_hub,
          presenter: Presenters::Repository,
          serializer: Serializers::Project
    end

    def self.for_standard_errors
      new loader: Loaders::StandardErrors.new,
          presenter: Presenters::StandardError,
          serializer: Serializers::StandardError
    end

    def self.for_system_errors
      new loader: Loaders::System::Errors.new,
          presenter: Presenters::System::Error,
          serializer: Serializers::System::Error
    end

    def self.for_system_signals
      new loader: Loaders::System::Signals.new,
          presenter: Presenters::System::Signal,
          serializer: Serializers::System::Signal
    end

    def self.for_text
      new loader: Loaders::Text.new, presenter: Presenters::Text, serializer: Serializers::Text
    end

    def initialize steps
      @steps = steps
    end

    def call content = nil
      loader.call(content)
            .map { |record| presenter.new record }
            .sort_by(&:label)
            .map { |record| serializer.new record }
            .then { |records| {items: records.map(&:to_h)} }
    end

    private

    attr_reader :steps

    def loader = steps.fetch(__method__)

    def presenter = steps.fetch(__method__)

    def serializer = steps.fetch(__method__)
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pennyworth-15.0.3 lib/pennyworth/processor.rb
pennyworth-15.0.2 lib/pennyworth/processor.rb
pennyworth-15.0.1 lib/pennyworth/processor.rb
pennyworth-15.0.0 lib/pennyworth/processor.rb
pennyworth-14.3.0 lib/pennyworth/processor.rb
pennyworth-14.2.1 lib/pennyworth/processor.rb
pennyworth-14.2.0 lib/pennyworth/processor.rb
pennyworth-14.1.2 lib/pennyworth/processor.rb
pennyworth-14.1.1 lib/pennyworth/processor.rb
pennyworth-14.1.0 lib/pennyworth/processor.rb
pennyworth-14.0.0 lib/pennyworth/processor.rb
pennyworth-13.8.0 lib/pennyworth/processor.rb
pennyworth-13.7.0 lib/pennyworth/processor.rb
pennyworth-13.6.0 lib/pennyworth/processor.rb
pennyworth-13.5.0 lib/pennyworth/processor.rb
pennyworth-13.4.0 lib/pennyworth/processor.rb
pennyworth-13.3.0 lib/pennyworth/processor.rb
pennyworth-13.2.0 lib/pennyworth/processor.rb