Class: Grumlin::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/grumlin/config.rb

Defined Under Namespace

Classes: ConfigurationError, UnknownProviderError

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
24
25
26
# File 'lib/grumlin/config.rb', line 21

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

Instance Attribute Details

#client_concurrencyObject

Returns the value of attribute client_concurrency.



4
5
6
# File 'lib/grumlin/config.rb', line 4

def client_concurrency
  @client_concurrency
end

#client_factoryObject

Returns the value of attribute client_factory.



4
5
6
# File 'lib/grumlin/config.rb', line 4

def client_factory
  @client_factory
end

#pool_sizeObject

Returns the value of attribute pool_size.



4
5
6
# File 'lib/grumlin/config.rb', line 4

def pool_size
  @pool_size
end

#providerObject

Returns the value of attribute provider.



4
5
6
# File 'lib/grumlin/config.rb', line 4

def provider
  @provider
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/grumlin/config.rb', line 4

def url
  @url
end

Instance Method Details

#middlewares {|@middlewares| ... } ⇒ Object

Yields:



28
29
30
31
32
33
34
# File 'lib/grumlin/config.rb', line 28

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

#validate!Object



36
37
38
39
40
# File 'lib/grumlin/config.rb', line 36

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

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