Sha256: 44eab0e6cbfde8479186b30670b277f45900416b6c9d6b7a56509b7179bc6c5c

Contents?: true

Size: 1.19 KB

Versions: 15

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

class Grumlin::Config
  attr_accessor :url, :pool_size, :client_concurrency, :client_factory, :provider

  SUPPORTED_PROVIDERS = [:neptune, :tinkergraph].freeze

  DEFAULT_MIDDLEWARES = Grumlin::Middlewares::Builder.new do |b|
    b.use Grumlin::Middlewares::SerializeToSteps
    b.use Grumlin::Middlewares::ApplyShortcuts
    b.use Grumlin::Middlewares::SerializeToBytecode
    b.use Grumlin::Middlewares::BuildQuery
    b.use Grumlin::Middlewares::CastResults
    b.use Grumlin::Middlewares::RunQuery
  end

  class ConfigurationError < Grumlin::Error; end

  class UnknownProviderError < ConfigurationError; end

  def initialize
    @pool_size = 10
    @client_concurrency = 5
    @provider = :tinkergraph
    @client_factory = ->(url, parent) { Grumlin::Client.new(url, parent: parent) }
  end

  def middlewares
    @middlewares ||= Grumlin::Middlewares::Builder.new do |b|
      b.use DEFAULT_MIDDLEWARES
    end
    yield(@middlewares) if block_given?
    @middlewares
  end

  def validate!
    return if SUPPORTED_PROVIDERS.include?(provider.to_sym)

    raise UnknownProviderError, "provider '#{provider}' is unknown. Supported providers: #{SUPPORTED_PROVIDERS}"
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grumlin-1.2.0 lib/grumlin/config.rb
grumlin-1.1.0 lib/grumlin/config.rb
grumlin-1.0.4 lib/grumlin/config.rb
grumlin-1.0.3 lib/grumlin/config.rb
grumlin-1.0.3.beta1 lib/grumlin/config.rb
grumlin-1.0.2 lib/grumlin/config.rb
grumlin-1.0.1 lib/grumlin/config.rb
grumlin-1.0.0 lib/grumlin/config.rb
grumlin-1.0.0.rc7 lib/grumlin/config.rb
grumlin-1.0.0.rc6 lib/grumlin/config.rb
grumlin-1.0.0.rc5 lib/grumlin/config.rb
grumlin-1.0.0.rc4 lib/grumlin/config.rb
grumlin-1.0.0.rc3 lib/grumlin/config.rb
grumlin-1.0.0.rc2 lib/grumlin/config.rb
grumlin-1.0.0.rc1 lib/grumlin/config.rb