Class: ActiveTriples::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/active_triples/configuration.rb,
lib/active_triples/configuration/item.rb,
lib/active_triples/configuration/merge_item.rb,
lib/active_triples/configuration/item_factory.rb

Overview

Class which contains configuration for RDFSources.

Defined Under Namespace

Classes: Item, ItemFactory, MergeItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, item_factory: ItemFactory.new, **options2) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • item_factory (ItemFactory) (defaults to: ItemFactory.new)
  • options (Hash) (defaults to: {})

    the configuration options. (Ruby 3+)

  • options2 (Hash)

    the configuration options. (Ruby 2.x)



16
17
18
19
# 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

Instance Attribute Details

#inner_hashObject

Returns the value of attribute inner_hash.



10
11
12
# File 'lib/active_triples/configuration.rb', line 10

def inner_hash
  @inner_hash
end

Instance Method Details

#[](value) ⇒ Object

Returns the configured value for an option

Returns:

  • the configured value



55
56
57
# File 'lib/active_triples/configuration.rb', line 55

def [](value)
  to_h[value]
end

#itemsHash{Symbol => ActiveTriples::Configuration::Item}

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

Returns:



44
45
46
47
48
49
# 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) ⇒ ActiveTriples::Configuration

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

Parameters:

  • options (Hash)

    configuration options to merge in.

Returns:



28
29
30
31
32
33
34
35
36
37
# 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_hHash{Symbol => String, ::RDF::URI}

Returns the available configured options as a hash.

This filters the options the class is initialized with.

Returns:

  • (Hash{Symbol => String, ::RDF::URI})


65
66
67
# File 'lib/active_triples/configuration.rb', line 65

def to_h
  inner_hash.slice(*valid_config_options)
end