Sha256: 4a66c808564531aa91a8594625df1608031f86521efab3b5016fa71943be410a

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

class Zilla::Versions::V20::Client
  include Zilla::Versions::V20

  include Memery

  attr_reader :json, :host, :scheme, :faraday_config_block, :faraday_config

  def initialize(json, host: nil, scheme: nil, faraday_config: {}, faraday_config_block: nil) # rubocop:disable Metrics/AbcSize
    @json = json
    @host = host || api.host || raise(ArgumentError, ":host must be specified")
    @scheme = (scheme || :https).to_s
    @faraday_config = faraday_config
    @faraday_config_block = faraday_config_block || ->(_f, _target) {}

    if api.schemes && !api.schemes.include?(@scheme)
      raise ArgumentError, "unsupported scheme #{@scheme.inspect}. Supported: #{api.schemes}"
    end

    define_operations!
  end

  memoize def api = API.new(json)

  memoize def executor = Executor.new(scheme, host, faraday_config:, faraday_config_block:)

  private

  def define_operations!
    api.endpoints.each do |endpoint|
      define_singleton_method(endpoint.operationId) do |*args, **params|
        executor.call(endpoint, *args, **params)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zilla-0.1.5 lib/zilla/versions/v20/client.rb
zilla-0.1.4 lib/zilla/versions/v20/client.rb