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(item_factory: ItemFactory.new, **options) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

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

    the configuration options.



15
16
17
18
# File 'lib/active_triples/configuration.rb', line 15

def initialize(item_factory: ItemFactory.new, **options)
  @item_factory = item_factory
  @inner_hash   = Hash[options.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



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

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:



43
44
45
46
47
48
# File 'lib/active_triples/configuration.rb', line 43

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:



27
28
29
30
31
32
33
34
35
36
# File 'lib/active_triples/configuration.rb', line 27

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})


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

def to_h
  inner_hash.slice(*valid_config_options)
end