class ActiveTriples::Configuration

Class which contains configuration for RDFSources.

Constants

CONFIG_OPTIONS

Attributes

inner_hash[RW]
item_factory[R]

Public Class Methods

new(options = {}, item_factory: ItemFactory.new, **options2) click to toggle source

@param item_factory [ItemFactory] @param [Hash] options the configuration options. (Ruby 3+) @param [Hash] options2 the configuration options. (Ruby 2.x)

# File lib/active_triples/configuration.rb, line 16
def initialize(options = {}, item_factory: ItemFactory.new, **options2)
  @item_factory = item_factory
  @inner_hash   = Hash[options.to_a + options2.to_a]
end

Public Instance Methods

[](value) click to toggle source

Returns the configured value for an option

@return the configured value

# File lib/active_triples/configuration.rb, line 55
def [](value)
  to_h[value]
end
items() click to toggle source

Returns a hash with keys as the configuration property and values as reflections which know how to set a new value to it.

@return [Hash{Symbol => ActiveTriples::Configuration::Item}]

# File lib/active_triples/configuration.rb, line 44
def items
  to_h.each_with_object({}) do |config_value, hsh|
    key = config_value.first
    hsh[key] = build_configuration_item(key)
  end
end
merge(options) click to toggle source

Merges this configuration with other configuration options. This uses reflection setters to handle special cases like :type.

@param [Hash] options configuration options to merge in. @return [ActiveTriples::Configuration] the configuration object which is a

result of merging.
# File lib/active_triples/configuration.rb, line 28
def merge(options)
  options    = options.to_h
  new_config = self.class.new(options)

  new_config.items.each do |property, item|
    build_configuration_item(property).set item.value
  end

  self
end
to_h() click to toggle source

Returns the available configured options as a hash.

This filters the options the class is initialized with.

@return [Hash{Symbol => String, ::RDF::URI}]

# File lib/active_triples/configuration.rb, line 65
def to_h
  inner_hash.slice(*valid_config_options)
end

Protected Instance Methods

build_configuration_item(key) click to toggle source
# File lib/active_triples/configuration.rb, line 71
def build_configuration_item(key)
  item_factory.new(self, key)
end

Private Instance Methods

valid_config_options() click to toggle source
# File lib/active_triples/configuration.rb, line 81
def valid_config_options
  CONFIG_OPTIONS
end